Passing a pointer to a derived class pointer
Hi Guys,
My mind has gone blank and I'm having a daft problem. I have a pointer:
cControl *m_Controller;
which i'm setting to a derived class:
m_Controller = new cPlayerControl();
Elsewhere I am then trying to set another m_Controller pointer in a class to the m_Controller above, with:
void Object::SetController (cControl *pController)
{
m_Controller = pController;
}
I am calling this function like this:
m_Object[0].SetController(m_Controller);
if I then call Update() on m_Controller in the same function, Update() will work and run.
But if I try and call m_Controller->Update() from within anywhere else in the Object class, simply nothing happens, the function is not run.
I'm assuming the pointers are getting messed up somewhere as Im setting a pointer to a derived class pointer?
Any help would be much appreciated, as I know it's something daft I'm just having one of those days! ;)
Cheers!
Quote:Original post by XaeronWhat does the debugger tell you? You can trace into the function to find out what function is being called. Is your Update() function virtual? If it's not, then the function called will depend on the type of the pointer.
if I then call Update() on m_Controller in the same function, Update() will work and run.
But if I try and call m_Controller->Update() from within anywhere else in the Object class, simply nothing happens, the function is not run.
I'm assuming the pointers are getting messed up somewhere as Im setting a pointer to a derived class pointer?
Any help would be much appreciated, as I know it's something daft I'm just having one of those days! ;)
Cheers!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement