-
Book Overview & Buying
-
Table Of Contents
C++ STL Cookbook - Second Edition
By :
The std::shared_ptr class is a smart pointer that owns its managed object and maintains a use counter to keep track of the number of references to the object so that the destructor may be called when the last copy of the shared_ptr is destroyed. This is distinct from a traditional "garbage collection" scheme which attempts to discover and reclaim unreachable objects automatically. This recipe explores the use of shared_ptr to manage memory while sharing ownership of the pointer.
For more detail about smart pointers, see the introduction to the recipe "Manage allocated memory with std::unique_ptr", earlier in this chapter.
In this recipe we examine std::shared_ptr with a demonstration class that prints when its constructors and destructor are called.
class Thing {
string_view thname{"unk"};
public:
Thing...
Change the font size
Change margin width
Change background colour