Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Viewing all articles
Browse latest Browse all 223

Comment by Peter - Reinstate Monica on How to Implement a Create() Function for Derived Classes in C++

$
0
0
@paddy In your example, I think it would be more illuminating to not use auto for the shared pointers; also, I would let Create() make return a shared_ptr of the actually created type, i.e. static std::shared_ptr<Derived> Create(). Due to shared_ptr's covariance, one can still use it to initialize a shared_ptr<Base> with it. Here is a minimally modified variation of your code.

Viewing all articles
Browse latest Browse all 223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>