Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Jan 18, 2000

Pure Virtual Destructors

Question:
I heard someone saying that C++ standardization does not allow pure virtual destructors not to have a definition.

As far as I know, this is not true. Could you please confirm? I cannot find the relevant information.

Answer:
It is true: a pure virtual destructor must be defined. The reason is that a derived object's destructor recursively calls its base class's destructor. When the base's destructor is only declared but not implemented (as is the case of a nonimplemented pure virtual destructor), the compiler issues an error message, and rightfully so. The implementation of a pure virtual destructor is located outside the class declaration, and it must be empty:

 
class A
{
public:
 virtual ~A()=0; //declaration
};

virtual A::~A()
{} //implementation
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date