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)