I'm using C++17. I'm trying to store class member functions in a vector. I've a class where I've several functions with same signature. My scenario is to store them in a vector and execute one by one. Consider this example:
class Test
{
int Func(const string& input, int index)
{
return 0;
}
public:
void Execute()
{
vector<function<int(const string&, int)>> exes;
exes.push_back(Test::Func);
}
};
int main()
{
Test test;
test.Execute();
cout << "Hello World!" << endl;
return 0;
}
When I try to compile it, I get the following error:
error: invalid use of non-static member function 'int Test::Func(const string&, int)'
exes.push_back(Test::Func);
~~~~~~^~~~
main.cc" data-line="13" data-column="9">main.cc:13:9: note: declared here
int Func(const string& input, int index)
How can I achieve this in C++17?