I'm not sure if this is possible in C++. I know you can pass a pointer to a function or static member function as a parameter. I want a function pointer for a specific object, so that when the function is executed, it is done on the object.
class MyClass
{
public:
MyClass(int id){mId = id;}
void execute(){cout<<mId<<endl;}
private:
int mId;
};
MyClass obj1(1);
MyClass obj2(2);
typedef (Executor)();
Executor ex1 = &obj1::execute();
Executor ex2 = &obj2::execute();
So when ex1 is executed, "1" should be printed and if ex2 is execute, "2" is printed. Is this possible?