C ++ virtual destructors

When creating prototype classes, I expose the destructor as such:

virtual ~MyClass();

When I finished the class in the library, I noticed that I could not add "virtual". Is this normal and virtually taken into account, or am I doing something wrong?

For instance; when I try to do this, I get a compiler error:

virtual MyClass::~MyClass() { }

Instead it works:

MyClass::~MyClass() { }

My question is that I do not need to include the virtualdestructor code in the final record, does the destructor still behave like a virtual destructor (since it is virtual as a prototype)?

+3
source share
2 answers

virtual - .

- , virtual .

+15

virtual ( ), . , .

+4

Source: https://habr.com/ru/post/1749966/


All Articles