I do not want to write in every class that I use shared_ptr or unique_ptr:
std::shared_ptr<Foo> p = CreateFoo();
I use this:
template <typename T> struct ptr_types { typedef std::shared_ptr<T> sptr; typedef std::unique_ptr<T> uptr; }; class A: public ptr_types<A> { public: A(){} int m; };
Then I can do it:
A::sptr p(new A);
Is this a design issue that inherits from my classes using smart pointers? Is there a more elegant solution?
EDIT:
Yes, I can use:
auto p = std::make_shared<A>();
but what about this:
std::shared_ptr<A> A::CreateA() { .... } void A::Sink(std::unique_ptr<A> p) { ... }
Better to have something like that?
A::sptr A::CreateA() { ... } void A::Sink(A::uptr p) { ... }
Maybe the question doesn't make sense ... and I'm lazy to write std :: blabla all the time in returned type functions or parameters.
source share