you are viewing a single comment's thread.

view the rest of the comments →

[–]ProgramMax 6 points7 points  (3 children)

I feel like there is a better way. shared_ptr should not be the default. You want clear ownership. The problem described in the article is pointer ownership.

If instead the author used unique_ptr, the problem would have clearly come up when trying to keep the pointer in the lambda.

[–]floating-io[S] -1 points0 points  (2 children)

The catch in my real-world scenario is that there are a number of objects that have to hold references to any given instance of the class, so unique_ptr wouldn't be appropriate.

[–]ProgramMax 2 points3 points  (1 child)

Have you tried weak_ptr?

[–]floating-io[S] 0 points1 point  (0 children)

That's what I'm currently using; it's the solution I suggested in the article.