Choosing a smart pointer is a choice of ownership strategy. You should ask yourself this question:
- Is
MainClass sole owner of the Buffer instance? Or does it make sense for the Buffer instance stored in MainClass to survive the MainClass object? (Or would it be reasonable if MainClass became a component of a larger system and lost the status of the application-life?)
If the answer makes sense, go with a generic pointer. If the answer is the sole owner / does not make sense, use what expresses a unique property - scoped_ptr (or std::unique_ptr , if available).
If you get a unique property, use the 'a' option to transfer the property. A function should only ever take a pointer parameter if the null pointer is valid for it.
If you end the co-ownership, two situations are possible. To transfer the buffer to locations sharing property, skip shared_ptr . To transfer it to places that simply observe / change, use "a" as above.
Angew source share