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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: C++
Expertise: All
Sep 17, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


A Pure Virtual Destructor

Unlike ordinary member functions, a virtual destructor is not overridden when redefined in a derived class. Rather, it is extended: the lower-most destructor first invokes the destructor of its base class and only then, it is executed. Consequently, when you try to declare a pure virtual destructor, you may encounter compilation errors, or worse: a runtime crash. However, there's no need to despair--you can enjoy both worlds by declaring a pure virtual destructor without a risk. The abstract class should contain a declaration (without a definition) of a pure virtual destructor:
 
	//Interface.h file
class Interface {
public:
		virtual ~Interface() = 0; //pure virtual destructor declaration
};
Somewhere outside the class declaration, the pure virtual destructor has to be defined like this:
 
	//Interface.cpp file
Interface::~Interface() 
{} //definition of a pure virtual destructor; should always be empty
Danny Kalev
 
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