if i want to dereference an object(using delete operator) of DERIVED class which is being referenced using a BASE class reference, which destructor would b called automatically??
BASE class destructor or DERIVED class destructor??
priyanka.js28
-2
Newbie Poster
Recommended Answers
Jump to PostYou need to make the destructor in the base class as virtual (otherwise the base class destructor will be called directly). Try this code:
#include <iostream> class base1 { public: virtual ~base1() { //notice virtual keyword here std::cout << "base1 destructor called!" << std::endl; }; }; class …
All 3 Replies
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
priyanka.js28
-2
Newbie Poster
arkoenig
340
Practically a Master Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.