Jump to content
  • Advertisement
Sign in to follow this  
CDProp

Inheritance and Constructors

This topic is 3544 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

It is my understanding that if you have two classes, Base and Derived, and you create an object of the Derived type, then Base::Base is called before Derived::Derived. I was wondering, if Base has multiple constructors, do you have any control over which one is called? Or is it always the default? If the latter is true, then I guess a default constructor is required? Edit: ugh, nevermind I already knew the answer to this. It's been a long day.

Share this post


Link to post
Share on other sites
Advertisement
Assuming C++, you may invoke a base class constructor like

Derived::Derived()
: Base( ... ) {
}

where ... represent the arguments the constructor. In this fashion you can call any of the accessible base class constructors. If you do not explicitly invoke the base class constructor, the default constructor for the base will be called instead. If that constructor is unavailable, the compiler will emit an error and you will need to make the constructor accessible or invoke a suitable parameterized base class constructor.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!