0

Possible Duplicate:
Why should I declare a virtual destructor for an abstract class in C++?

I inherited some code here I'm trying to understand, and the header file is:

class RemoteNotify : public virtual ServiceObject, public virtual RemoteMsg{
      RemoveNotify();
      virtual ~RemoveNotify();
      /* more code down here */
}

I would like to know why someone would declare a virtual destructor?

Community
  • 1
  • 1
cybertextron
  • 10,547
  • 28
  • 104
  • 208
  • So that deleting a pointer-to-base calls the most-derived dtor. – Xeo Jul 30 '12 at 15:55
  • 2
    You should probably read some introductory text on C++ – David Rodríguez - dribeas Jul 30 '12 at 15:55
  • 2
    On this regard, probably the correct question should be: why doesn't the compiler enforce a virtual destructor if the class has virtual members ? – Stefano Borini Jul 30 '12 at 15:56
  • @StefanoBorini: I would assume that is based on the principle that you don't pay for things you don't need. Just because you have virtual members does not mean that you absolutely need a virtual destructor (you might always know the correct type at the point of deletion. Of course there is nothing keeping the compiler from warning in this case. – Grizzly Jul 30 '12 at 16:13

0 Answers0