I have here a minimized version of code below, that won't compile.
#include<iostream>
#include<vector>
#include<set>
template<int D>
class Points{
public:
std::vector<int> data;
void func1()
{
// some operation on data which depends on D
std::cout<<"Operation 1 which is " <<"D \n";
}
void func2()
{
// some operation on data which depends on D
std::cout<<"Operation 2 which is " <<"D \n";
}
void execute_all(std::vector<void (Points::*)()> flist)
{
for (auto f: flist){
(this->* f)();
}
}
};
template<int D>
using fptr = void (Points::*)();
int main()
{
constexpr D = 2;
Points p;
std::set<fptr<D>> functionlist;
functionlist.insert(&(Points<D>::func1));
functionlist.insert(&(Points<D>::func2));
p.execute_all(functionlist);
return 0;
}
My intention is to group together function pointers, that I can pass to the member function in order to execute them together. In my intended code (not shown here) the "execute_all" happens in a deeply nested loop, with local arguments. I tried to run the above, even without a template class, but even that won't compile: invalid use of non-static member function ‘void Points::func1()’
Please help by pointing me to the issues with my code, and possibly providing a corrected version, that executes all functions func1 and func2 as intented.
execute_allfunction? What is the type of argument it expects? Is the code you show us really a proper minimal reproducible example?template<int D>using fptr = void (Points<D>::*)();and your function expect a vector and receive a set, you must choosetemplate<It> void fun(It first, It end)? Just like any function in the standard library.