Jump to content
  • Advertisement
Sign in to follow this  
spraff

CMyClass: Am I a daddy?

This topic is 3625 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 there. Without RTTI, is there a way for a virtual C++ destructor to determine if it has been overridden in a subclass?

Share this post


Link to post
Share on other sites
Advertisement
By the time the destructor is reached, all subclasses of the current class have already been destroyed and all subclassing information is probably gone with it. The open-closed principle dictates that you shouldn't know who inherits from you anyway, so I suspect there might be a shorter, faster and more elegant alternative. So, why do you need this functionality?

Share this post


Link to post
Share on other sites
P.S. I know I can add another virtual method which sets a flag, but I'd rather not change the class's interface.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
By the time the destructor is reached, all subclasses of the current class have already been destroyed and all subclassing information is probably gone with it. The open-closed principle dictates that you shouldn't know who inherits from you anyway, so I suspect there might be a shorter, faster and more elegant alternative. So, why do you need this functionality?


It's debug code to help me trace what's happening. The parent class knows something about its subclasses in this situation, so traditional principles are already being fudged a bit.

Share this post


Link to post
Share on other sites
Quote:
Original post by spraff
It's debug code to help me trace what's happening. The parent class knows something about its subclasses in this situation, so traditional principles are already being fudged a bit.


Short of storing an is_most_derived variable (which is overwritten by derived classes to equal false) you won't be able to know whether a derived class once exists. That, or using a compiler-specific extension (can't think of any that does this, though, but there could be).

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!