could you please help me how to handle (initialize, call) std::array of structs of std::function. Code like below:
class A
{
struct Functions
{
std::function<bool()> handler1;
std::function<bool()> handler2;
};
bool foo1();
bool foo2();
bool foo3();
bool foo4();
std::array<Functions, 2> Func_Arr;
};
I would like to map something like:
Func_Arr[0].hanlder1 = foo1;
Func_Arr[0].hanlder2 = foo2;
Func_Arr[1].hanlder1 = foo3;
Func_Arr[1].hanlder2 = foo4;
and then call only proper handler
I cannot figure out how to handle it, I mean how to mapp functions foo1 and foo2 to the struct and then call them via Func_Arr.
Tried to compile many times but failed
A::foo1, you need an instance ofA.Functionselements in the array. IsA::foo1supposed to call theFunctions::foo1method in both of them?fooX.staticmember functions need an instance of the class to operate on. Either make your functionsstatic, usestd::function<bool(A*)>, or wrap them in lambdas that capture an instance ofA.