#include #include using std::cout; using std::endl; using std::boolalpha; using std::weak_ptr; using std::shared_ptr; int main(){ cout << boolalpha<< endl; auto sharedPtr=std::make_shared(2011); weak_ptr weakPtr(sharedPtr); cout << "weakPtr.use_count(): " << weakPtr.use_count() << endl; cout << "weakPtr.expired(): " << weakPtr.expired() << endl; if(shared_ptr sharedPtr1 = weakPtr.lock()) { cout << "*sharedPtr: " << *sharedPtr << endl; } else{ std::cout << "Don't get the resource!" << std::endl; } weakPtr.reset(); if(shared_ptr sharedPtr1 = weakPtr.lock()) { cout << "*sharedPtr: " << *sharedPtr << endl; } else{ cout << "Don't get the resource!" << endl; } cout << endl; }