Questions tagged [enable-shared-from-this]

36 questions
0
votes
0 answers

Ownership sharing with smart pointers while object initialization

I have a class A that has a member pointer to class B: class A { public: A() { m_b = createB(); } std::shared getSpB() { return m_b; } private: std::shared m_b; }; class B { public: B()…
0
votes
1 answer

Why doesn't std::enable_shared_from_this use a mutable std::weak_ptr?

I understand that most std library implementations choose to implement std::enable_shared_from_this by storing a std::weak_ptr in the base class. This leads to the following: #include class Foo : public…
Joshua W
  • 1,103
  • 12
  • 29
0
votes
1 answer

Assertion to enforce creation of object as shared_ptr?

When using std::shared_ptr it can often be useful to make use of std::enable_shared_from_this so that you have access to the shared_from_this() function. One requirement of using shared_from_this() is that all instances of the object are…
Adam Stark
  • 422
  • 1
  • 5
  • 12
0
votes
1 answer

Empty weak pointer in enable_shared_from_this

After publicly inheriting enable_shared_from_this and initialzing the object of class, while calling another function of that class, i can still see empty weak pointer of enable_shared_from_this_class while debugging in Visual Studio. All existing…
-1
votes
1 answer

swap method for a class inherited from enable_shared_from_this<...>

I have implemented a swap method for my class that inherits from enable_shared_from_this<...> class X : public enable_shared_from_this { int x; friend void swap(X& x1, X& x2) { using std::swap; swap(x1.x, x2.x); } …
traveh
  • 2,700
  • 3
  • 27
  • 44
-1
votes
1 answer

enable_shared_from_this returns bad_weak_ptr error

I am using boost library in my project. While I was writing rest http client code I got this error. libc++abi.dylib: terminating with uncaught exception of type std::__1::bad_weak_ptr: bad_weak_ptr template 21 class Http: public…
wwwwe
  • 127
  • 1
  • 7
1 2
3