Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

virtual destuctor

Posted on 2011-03-04
6
294 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

840 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