Weak pointers are used to locate an object in memory without increasing its reference count or keeping it alive. The code demonstrates creating a weak pointer to a shared pointer within a local scope, so the shared pointer is destroyed but the weak pointer can still access the object.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views1 page
Weak Pointers
Weak pointers are used to locate an object in memory without increasing its reference count or keeping it alive. The code demonstrates creating a weak pointer to a shared pointer within a local scope, so the shared pointer is destroyed but the weak pointer can still access the object.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
// Weak pointers
// we use weak pointers to locate a specific obj in memory
//it wont keep the value and wont raise the number of owners #include <iostream> #include <memory> using namespace std; class MyClass { public: MyClass() { cout << "Constructor is invoked" << endl; } ~MyClass() { cout << "Destructor is invoked" << endl; }