FAQ Database Discussion Community


Constructor taking shared_ptr

c++,c++11,typedef,shared-ptr,make-shared
I have situation like this struct Foo { Foo(int x, int y) : x(x), y(y) { } int x, y; }; class Bar { public: typedef std::shared_ptr<const Foo> ConstFooPtr; typedef std::shared_ptr<Foo> FooPtr; Bar(int index = 0, FooPtr ptr = FooPtr()) : index_(index), ptr_(ptr) { } private: ConstFooPtr ptr_; int index_;...

std::shared_ptr(new DerivedType(…)) != std::make_shared(DerivedType(…))?

c++,c++11,shared-ptr,c++-standard-library,make-shared
I haven't found any issues quite like this yet: but if someone finds one then sorry. I've been trying to use std::shared_ptr to greatly simplify memory management, however I've come across what must be some sort of bug. When I create a DerivedType pointer with std::make_shared<type>(DerivedType(...)) It can only be...