Example for discussion
counted_ptr<T> ptr(new T());
- needs a counter
- allocation could fail
- so may constructor throw?
- and should it delete initialiser?
Notes:
There are a number of possible ways to implement counted_ptr…
- Prevent the constructor throwing exceptions (at the cost of possible exceptions in copy ops - e.g. assignment)
- The constructor throws, and the user code is responsible for deleting the T.
- Should an exception occur, then the counted_ptr deletes the T.