Sorry, I messed up:
Kai-Uwe Bux wrote:
Tony Johansson wrote:
Hello Experts!!
Assume I have a base class called animal. I want this class to be
abstract so I make the destructor pure virtual by having this statement.
virtual ~Animal() = 0;
Destructor will never be inherited.
Huh?
Now to my question why do I have to give a body {} at least the empty
body to the pure virtual destructor.
You don't.
Actually, you do because C++ standard (12.4/7) says you shall at least if
your program is going to create objects of type Animal (or any derived
type). Now, if you would not want to create such objects, why would you
have the class in the first place?
What's the difference between
virtual ~Animal() = 0; and virtual ~Animal() = 0 {};
virtual ~Animal() = 0;
is valid C++.
virtual ~Animal() = 0 {};
will not compile.
Normally when you have pure virtual destructors you almost never give any
kind of body to the function.
"almost"?
Goes for pure virtual functions (otherwise, why make them pure in the first
place), but destructors are special: they get called from destructors of
derived classes. Thus, they better be defined even for an abstract base
class. (That seems to be the rational behind 12.4/7.)
Best
Kai-Uwe