Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Passing a pointer to a derived class pointer

Started by Xaeron Oct 14, 2008 at 8:37 AM 0 replies 700+ views
Original Post
Xaeron
Xaeron
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!
Evil Steve
Evil Steve
Quote:
Original post by Xaeron
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!
What 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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.