2 ms·
It is actually super easy, barely an inconvenience, as long as you know the actual dynamic type at construction time. For example shared-ptr to base can correc
by gpderetta 3y ago
It is actually super easy, barely an inconvenience, as long as you know the actual dynamic type at construction time.
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.
- brtv 3y agoYou always know the actual dynamic type at construction time, how would you otherwise construct it? > For example shared-ptr to base can correctly invoke the correct derived type Invoke what exactly? Im sorry I don't understand what you're trying to say here. I guess you can force all derivied types to implement a clone() function, such that box<T> can do the deep copy, but Id consider that a fairly big inconvenience for such a simple pointer type.
- gpderetta 3y agoNo need for T to have a clone function. You can use standard type erasure techniques. Consider how std:: function or std::any is implemented.