Smart Pointers in C++ Are Not Pointers
summary
Explains that raw pointers and references support covariant returns but smart pointers do not because unique_ptr is a class not a built in pointer type so overriding a virtual that returns std::unique_ptr<Super> with std::unique_ptr<Sub> fails to compile. Shows small code example demonstrating the compile error and the simple workaround of providing an overload that returns the concrete smart pointer type. Notes this is a language limitation not a design flaw.
AI-written summary · about








