Sign in to follow this  
Xaeron

Passing a pointer to a derived class pointer

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this