David Côme wrote:
Quote:
Hello everybody.
I have a question.
When i want use a pure virtual destructor in one of my classe, i must
give a definition of this destructor like this:
>
class A
{
//a lot of things
virtual ~A() =0;
};
>
A::~A()
{
//....
}
>
However,i ask myself why ?
Does anyone have one reponse ?
If you ever derive from your class A, an instance of it will have
to be destructed at some point, most likely (unless all you do is
dynamically allocate the derived classes and never deallocate them
in your program). If your destructor is pure and not implemented,
then an attempt to destruct an instance of 'A' will result in
a call to a pure virtual function, which has undefined behaviour.
To avoid undefined behaviour you need to provide the implementation
for A::~A. That's one response I have.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask