How to create a function pointer to any class function knowing only arguments and return type? How to call this function later?
I read about std::function, however I do not have an idea how to implement it without using specific class name like "std::function<void(const ClassName&, int)> f_add_display = &ClassName::func;
"
The example below is NOT for compiling, it is only to show the idea I mean:
class collection {
p* ...; //pointer to any(!) class function with known arguments and return type
} _collection;
class One {
public:
...
bool Foo_1(int, int) {};
void saveFuncAddr() {_collection.p = this::Foo_1};
};
class Two {
public:
bool Foo_2(int, int) {};
void saveFuncAddr() {_collection.p = this::Foo_2};
};
int main() {
one* = new One();
one->saveFuncAddr();
bool res1 = (*_collection.p)(1, 2);
two* = new Two();
two->saveFuncAddr();
bool res2 = (*_collection.p)(1, 2);
}