I have seen a number of examples how to make a function pointer to a C++ class non-static member of a specific class type. However, I would have use for such pointer that would work for any type class. To demonstrate the idea, I wrote a pseudo example:
class A
{
public:
A(){} //constructor
void callMe() { /* do something */ }
};
class B
{
public:
B(){} //constructor
void callMe() { /* do something */ }
};
main()
{
A aa;
B bb;
//pseudo part:
generic_method_pointer_type p; //how to define the type of p?
p=HOWTO;//set pointer p to point to A::callMe. How to do?
p(aa); //A::callMe on instance aa gets called
p=HOWTO;//set pointer p to point to B::callMe. How to do?
p(bb); //B::callMe on instance bb gets called
}
Does this look possible?
I know C++11 has new tricks such as std::function for this. I did some experiments on std::function and found it too slow for a real-time app running on a small microcontroller. That is why I would prefer direct hard coded pointers which would cause minimum overhead.
Thank you for your advice!