Advertisement Jump to content
Sign in to follow this  
raptorstrike

Overiding Method In Base Constructor

This topic is 4905 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.

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!