Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • shared_ptr<> would be a better fit here than unique_ptr<>, since its not unlikely the ptr would be needed in more than one place (due to how gui frameworks usually work - like list of buttons associated with a page, list of things with callbacks etc). Commented Jul 25, 2018 at 13:35
  • @LewisPringle no, you have exactly one place which owns the std::unique_ptr<button>, and a bunch of other places that reference it ( button &) Commented Jul 25, 2018 at 14:44
  • @LewisPringle unique_ptr is convertible to shared_ptr and does not have it's added cost of atomic reference counting. Commented Jul 25, 2018 at 15:23
  • @Caleth if you are going to use references, you may as well not be using smart pointers of any kind. The reference is an unsmart pointer. Commented Jul 25, 2018 at 15:49
  • @LewisPringle when you can avoid using pointers of any kind, you definitely should. In OP's case pointers are only required due to legacy API. Commented Jul 25, 2018 at 15:51