1

When using std::shared_ptr<> it is a bug when converting a this pointer to a std::shared_ptr<> isn't it?

struct A
{
    std::shared_ptr<A> getSomething(void)
    {    return std::shared_ptr<A>(this);
    }
};
int main(int, char**)
{    std::make_shared<A>()->getSomething();
}

Suggestions?

  • 2
    [std::enable_shared_from_this](http://en.cppreference.com/w/cpp/memory/enable_shared_from_this) – Piotr Skotnicki Oct 31 '17 at 18:22
  • some people (like me) might now know this feature and search for different things... The other question is not a question but the answer to this question. –  Oct 31 '17 at 18:33
  • @FrankPuck: "*some people (like me) might now know this feature and search for different things...*" Which is why we labeled this as a duplicate of that. It's not that we expected you necessarily to find it; it's that we don't need two answers for the same thing. – Nicol Bolas Oct 31 '17 at 18:47

0 Answers0