Six-week program reading-deep copy, Friends, class templates (3)

Source: Internet
Author: User

Code

#include <iostream>using namespace Std;class b{public:    B ()    {        cout<< "default constructor" <<endl;    }    ~b ()    {        cout<< "destructed" <<endl;    }    B (int i):d ata (i)    {        cout<< "constructed:" << data <<endl;    } Private:    int data;}; b Play (b b) {    return B;} int main () {    B temp = Play (5);    return 0;}


Operation Result:

Summary of Knowledge points:

1)

b temp = play (5);//Call the Play function, cast argument 5 to the Type B object to parameter B when the parameter constructor is called to create object B, print constructed by PARAMETER5, the function executes the process of printing mytest!, after the function executes, B is out of scope, is freed, calls the destructor to print destructed, calls the default copy constructor in the main function to generate the object temp, the main function ends, temp is freed, and the destructor is called to print destructed

2) B (int i):d ata (i)

Cast pass-through value

Learning experience:

Good study Day Day up

Six-week program reading-deep copy, Friends, class templates (3)

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.