Solved

virtual destuctor

Posted on 2011-03-04
6
291 Views
Last Modified: 2012-05-11
I have seen following in my appln.

class A {

virtual ~A();
}

class B : public A {
  B()
}

Inside B.cpp, the function ~A() and ~B() both is missing

Shouldn't the base class destructor MUST be defined in child class
0
Comment
Question by:learningunix
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 35039432
Virtual destructors only guarantee for the calling order, nothing else - you don't necessarily have to provide an explicit destructor in a derived class, the compiler will create a default destructor that will then be chained in the sequence - see also http://www.codersource.net/c/c-miscellaneous/c-virtual-destructors.aspx
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 35041693
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.

0
 
LVL 86

Expert Comment

by:jkr
ID: 35041726
DeepuAbrahamK, it's always a good idea to quote your sources: http://www.codeguru.com/forum/archive/index.php/t-445242.html

STLDude
February 4th, 2008, 10:58 AM
A little more info:
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.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 35041767

class A
{
public:
      A()
      {
            cout<<"I am inside the ctor : A"<<endl;
      }

    virtual ~A()
      {
            cout<<"I am inside the dtor : A"<<endl;
      }
};

class B:public A
{
public:
      B()
      {
            cout<<"I am inside the ctor : B"<<endl;
      }

    virtual ~B()
      {
            cout<<"I am inside the dtor : B"<<endl;
      }
};


int main () {
  A* a = new B();
  delete a;
}
0
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 35041775
I found that statement is very crisp:
pleasw refer : http://www.devx.com/tips/Tip/12729
0
 

Author Closing Comment

by:learningunix
ID: 35046552
thx
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now