1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-19 13:02:14 +02:00

More explanation on virtual destructors

This commit is contained in:
Alva Connor Waters
2015-10-02 15:55:05 +00:00
parent ae86e4ebab
commit 455afa3a7b

View File

@@ -349,7 +349,10 @@ public:
// These are called when an object is deleted or falls out of scope.
// This enables powerful paradigms such as RAII
// (see below)
// Destructors must be virtual to allow classes to be derived from this one.
// Destructors should be virtual if a class is to be derived from;
// if they are not virtual, then any resources allocated using RAII in
// the derived class will not be released if it destroyed through a
// base-class reference or pointer.
virtual ~Dog();
}; // A semicolon must follow the class definition.