I'm using this base functor class and object functor class from the Enginuity articles but I'm having problems creating CObjFunctor objects..
class IBaseFunctor
{
public:
virtual void operator()() = 0;
};
template <class T>
class CObjFunctor: public IBaseFunctor
{
private:
//Function pointer typedef
typedef void (T::*cof_ptr)();
T *m_Object; //Object pointer
cof_ptr m_Function; //Function pointer
public:
//Assign an object and function pointer to this functor
CObjFunctor(T *pObj, cof_ptr *pFunc) { m_Object = pObj; m_Function = pFunc; }
//Call the function
void operator()() { (m_Object->m_Function)(); }
};
My code is as shown below
//Class that uses a CObjFunctor object
class CTimer
{
//...
CObjFunctor<CTimer> *m_functor;
//...
};
//Code where my problems are
CTimer::CTimer()
{
m_functor = new CObjFunctor<CTimer>(this, &CTimer::Pause);
//...
}
VC++ 2003 is giving me this error on the line where I call new to create the functor:
error C2664: 'CObjFunctor<T>::CObjFunctor(T *,CObjFunctor<T>::cof_ptr * )' : cannot convert parameter 2 from 'void (__thiscall CTimer::* )(void)' to 'CObjFunctor<T>::cof_ptr * '
with
[
T=CTimer
]
and
[
T=CTimer
]
There is no context in which this conversion is possible
Any ideas what I'm doing wrong? The CObjFunctor class should be able to hold a pointer to an object along with a pointer to a member function of that object and then to call said function from anywhere in the program.
I appologise for basically posting a load of code, I try to make my requests for help as specific as possible in order to avoid confusion but this time I'm completely stumped and don't have the slightest idea where to start.