• Advertisement
Sign in to follow this  

Virtual destructor?

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

Hiya, I have an interface in my C++ library which the client code should not be able to instance or destroy, so I have just ommitted the ctor and dtor from the class declaration - IIRC this has the desired effect. The destructor really needs to be virtual though as other classes will inherit from it - what is the correct way of achieving this? Should I just make the interface's destructor protected and virtual? Thanks for any help :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:

Should I just make the interface's destructor protected and virtual?

If I understand you correctly, then yes.

You can also make the constructor protected or private to deny instances
to be created.

Share this post


Link to post
Share on other sites
OK thanks. Don't the constructor/destructor default to private though, if you don't declare them yourself?

Share this post


Link to post
Share on other sites
If you don't define the default constructor, copy constructor, copy assignment operator or destructor yourself, the compiler will generate default ones for you when necessary. These are public by default - unless you define them yourself. ;)

Share this post


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

  • Advertisement