The aim of the following code is to store and call member functions on an
object.
class C {};
class CF
{
public:
template<typename T> inline CF(T& o, void (T::*f)())
: pO(&o), pF( (void (C::*)()) f) {};
inline void Call() { (pO->*pF)(); };
void (C::*pF)();
C* pO;
};
class A : public C
{
public:
void F() {};
};
int main()
{
A a;
CF f(a, A::F);
f.Call();
}
Objects of type CF will be stored in an array (or container) and may call
functions from different classes. Performance and memory comparisions with
virtual functions would depend on usage.
My question: since class C appears to have little impact other than allowing
compilation, can this be written without C? What other alternatives are
there (with type generic storage)?
Regards,
cadull