| 87 | } |
| 88 | |
| 89 | void smart_pointers() |
| 90 | { |
| 91 | BankAccount* a = new CurrentAccount(123); |
| 92 | a->deposit(321); |
| 93 | delete a; |
| 94 | |
| 95 | // << will not work if you make this a shared_ptr<BankAccount> |
| 96 | auto b = make_shared<CurrentAccount>(123); |
| 97 | |
| 98 | BankAccount* actual = b.get(); // pointer's own operations on a . |
| 99 | b->deposit(321); // underlying object's operations are on -> |
| 100 | // note this expression is identical to what's above |
| 101 | cout << *b << endl; |
| 102 | // no delete |
| 103 | |
| 104 | // see shared_ptr in file structure window |
| 105 | } |
| 106 | |
| 107 | struct Pingable |
| 108 | { |