Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 04cpp3/sec01Inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Virtual functions open up fully polymorphic behaviour for our classes, and are i
- Defining a container of objects which can be of different derived classes by declaring a container using the base class.
- We will return to this technique later when we discuss pointers, you cannot have a container, such as `vector`, of references. Nevertheless it is good to be aware of this use case now as it is a very common way for polymorphism to come in handy!

**N.B.** Special consideration should be given to _virtual destructors_. **If your class is inherited from, the destructor should usually be virtual.** We can point to an object of the derived class using a pointer of the type of `Base *`. If we `delete` this base pointer to free the memory then _only the base class destructor will be called_, and anything that needs to be cleaned up by the derived destructor will not happen. If the destructor is virtual, then the derived destructor will be called (which also calls the base destructor), and so any necessary clean up will happen. If you use _Smart Pointers_ to initialise your object then the correct (derived) destructor should be used even if the base destructor is not virtual.
**N.B.** Special consideration should be given to _virtual destructors_. **If your class is inherited from, the destructor should be virtual.** We can point to an object of the derived class using a pointer of the type of `Base *`. If we `delete` this base pointer to free the memory then _only the base class destructor will be called_, and anything that needs to be cleaned up by the derived destructor will not happen. If the destructor is virtual, then the derived destructor will be called (which also calls the base destructor), and so any necessary clean up will happen.

## Abstract Classes

Expand Down
Loading