|
|
|
|
|
by brtv
1031 days ago
|
|
> std::box<T> addresses these issues by offering deep copying and automatic garbage collection This is pretty much impossible when holding a pointer of base class. However, this is a primary reason for having pointers in the first place (polymorphism, and having abstract base classes). In all other cases, you're probably better off with either the raw value, std::variant or std::reference_wrapper. |
|
For example shared-ptr to base can correctly invoke the correct derived type destructor even if the destructor is not virtual.
Edit: accidentally a word.