Exercise 13.6
is actually the "=" operation, which is the assignment operation. The right operand is passed as a display parameter to the left. Synthetic copy assignment operators prohibit assignment of objects of that type. When a class does not define its own copy assignment operator, the compiler automatically generates a synthetic copy assignment operator for it.
Exercise 13.7
Assigning one strblob to another strblob this operation is completely non-problematic.
When the assignment is strblobptr, it will be error, when compiling the error, the left and right values of the type is different (also not the inheritance relationship), can not complete the assignment.
Exercise 13.8
1#include <iostream>2#include <string>3#include <memory>4 5 using namespacestd;6 7 8 classHasptr {9Friend Ostream &print (ostream &os, Hasptr &h);Ten Public: OneHasptr (Const string&s =string()): PS (New string(s)), I (0) {} AHasptr (ConstHasptr &ptr); -Hasptr &operator=(ConstHasptr &PT); - Private: the string*PS; - inti; - }; - +Ostream &print (ostream &os, Hasptr &h); - + intMain () A { atHasptr has ("Hello"); -Hasptr has =has ; - print (cout, have); -System"Pause"); - return 0; - } in -Hasptr::hasptr (ConstHasptr & PTR): PS (New string(*(ptr.ps))), I (PTR.I) {} to +Hasptr & Hasptr::operator=(ConstHasptr &PT) - { thePS =New string(*pt.ps); *i =pt.i; $ return* This;Panax Notoginseng //TODO: Insert a return statement here - } the +Ostream & Print (ostream & OS, Hasptr &h) A { theOs << *h.ps << h.i <<Endl; + returnos; - //TODO: Insert a return statement here $}
C++primer 13.1.2 sessions