Jump to content
  • Advertisement
Sign in to follow this  
beebs1

Virtual destructor?

This topic is 4167 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
Quote:
Original post by beebs1
OK thanks. Don't the constructor/destructor default to private though, if you don't declare them yourself?


No. Any generated constructors or destructors will default to public.

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
×

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!