C++primer 13.1.2 sessions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.