Loading…
CppCon 2020 has ended
Back To Schedule
Thursday, September 17 • 09:00 - 10:00
Back to Basics: Smart Pointers

Log in to save this to your schedule, view media, leave feedback and see who's attending!

Feedback form is now closed.
From the library's perspective, an essential feature in C++11 was smart pointers.

Since C++11, we have four different smart pointer: std::auto_ptr, std::unique_ptr, std::shared_pointer, and std::weak_ptr. With C++17 std::auto_ptr was removed and with C++20, we get an std::atomic<std::shared_ptr>, and std::atomic<std::weak_ptr>.

Each smart pointer models a specific ownership semantic and has a particular purpose. The crucial question is, therefore: When should you use which smart pointer? The answer to this question becomes more sophisticated when you think about the arguments or the return value of a function. You have to answer the following question for the function arguments:

- What does it mean to take the function arguments by pointer, by std::unique_ptr, or by std::shared_ptr?
- Should the function take the smart pointer by value or by reference?
- Should the argument be const or not?

The answers to those questions are not the end of the story. When you have a factory function creating something, the question immediately arises: Should the factory function return its product by a pointer, by std::unique_ptr, or by std::shared_ptr?

Smart pointers are more than pointers decorated with smartness. Smart pointer models ownership semantic. Understanding the ownership semantic of smart pointers is the main topic of my talk and, therefore, your takeaway.

Speakers
avatar for Rainer Grimm

Rainer Grimm

Trainer, Modernes C++
Rainer works as a software architect, team lead, and instructor since 1999. In 2002, he created a further education round at his company. He gives seminars since 2002. Rainer's first seminars were about proprietary management software, but seminars for Python and C++ followed immediately... Read More →


Thursday September 17, 2020 09:00 - 10:00 MDT
Back to Basics