Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

Overiding Method In Base Constructor

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

If you have a base constructor Base::Base_Constructor() { Do_Something(); }; then you have a derived class Derived::Derived_Constructor() : Base_Constructor() { }; if you were to override Do_Something() in the Derived class would it have effect on the call in the base constructor (when its called in the derived constructor that is)? and if not what would be the work around if you wanted to do something like this? thx for all your help =)

Share this post


Link to post
Share on other sites
Advertisement
You mean like this?


struct Base {
Base() {
doSomething();
}
virtual void doSomething {
// base impl
}
}

struct Derived : Base{
Derived() : Base() {}
void doSomething {
// derived impl
}
}



Answer: No. See here.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It is undefined behaviour to call virtual functions in a base ctor.



// ville

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry Zahlman, I completely lost your correct answer into your .sig noise the first time.


// ville

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!