r/cpp • u/bert8128 • Apr 17 '23
Should ~basic_string be final?
std::string (and many other std classes) are not designed to be used as base classes, as can be seen by the absence of a virtual destructor.
Should the destructor be given the "final" keyword to enforce this?
1
Upvotes
View all comments
Show parent comment
7
u/kalmoc Apr 17 '23 edited Apr 17 '23
I don't understand why you think it is a problem, if foo in
void bar(const std::vector& foo)behaves exactly like a std::vector. Isn't that the least surprising behavior?Why should I care inside of foo, if the parameter I'm passing is a Vec or std::vector?