1#include <iostream>
2#include <memory>
3
4void report(std::shared_ptr<int> ptr) {
5 if (ptr) {
6 std::cout << "*ptr=" << *ptr << "\n";
7 } else {
8 std::cout << "ptr is not a valid pointer.\n";
9 }
10}
11
12int main() {
13 std::shared_ptr<int> ptr;
14 report(ptr);
15
16 ptr = std::make_shared<int>(7);
17 report(ptr);
18}
19//output:
20//ptr is not a valid pointer.
21//*ptr=7