Chapter 31. Smart Pointer Members, Part 2: Toward a ValuePtr
Difficulty: 6
Can we make life safer for ourselves and our users by devising a smart pointer class designed specifically for class membership?
Write a suitable
ValuePtr
template that is used as shown here:// Example 31-1 // class X { // ... private: ValuePtr<Y> y_; };
to suit three specific circumstances:
Copying and assigning
ValuePtr
s is not allowed.Copying and assigning
ValuePtr
s is allowed and has the semantics of creating a copy of the ownedY
object using theY
copy constructor.Copying and assigning
ValuePtr
s is allowed and has the semantics of creating a copy of the ownedY
object, which is performed using a virtualY::Clone()
method if present and theY
copy constructor otherwise. ...
Get More Exceptional C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.