Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

Method override question

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi gamedev, I have a base class called Object which has a virtual Startup and Shutdown. In the constructor it calls Startup and checks to see if the object was created succesfully. The destructor calls shutdown to release allocated memory. My question is the the derived class, lets say Application which creates the window. I override the Startup method in the Application class, but it calls the Object startup not the override. Can this work like this, or since I am calling the Startup method in the base class Object it will call the base method Startup and not the override?

Share this post


Link to post
Share on other sites
Advertisement
Assuming C++, virtual functions called in constructors and destructors are not bound to a derived class' version. If in Object you call Startup(), it will call Object::Startup().

If you have something that your derived class needs to do when constructed, it should probably do it in the derived class' constructor. Similarly, if there is something a derived class needs to do when destroyed, that functionality should be in the derived class' destructor.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!