You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

01-std-shared-ptr.cc 279 B

123456789101112
  1. #include <memory>
  2. #include <iostream>
  3. void foo(std::shared_ptr<int> p) {
  4. (*p)++;
  5. }
  6. void create() {
  7. std::shared_ptr<int> p = std::make_shared<int>(42);
  8. foo(p);
  9. // p is still valid
  10. std::cout << *p << std::endl;
  11. } // when leaving this scope, p will be destroyed (deleted)