When creating prototype classes I lay out the destructor as such:
virtual ~MyClass();
When finalizing the class in a library I noticed that I cannot add ‘virtual’. Is this normal, and is virtual taken into consideration or am I do something wrong?
For example; when I try to do this I get a compiler error:
virtual MyClass::~MyClass() { }
Instead doing this works:
MyClass::~MyClass() { }
My question is since I do not have to include virtual in the final code write of the destructor does the destructor still behave as a virtual destructor (since it is virtual as a prototype)?
The
virtualkeyword is only used as part of the member function declaration inside of the class definition.If the member function is defined outside of the class definition, the
virtualkeyword is not placed there.