First, the previous paragraph is simple.Code:
# Include <iostream>
Using namespace STD;
Class Test
{
Public:
Test ()
{
Cout <"default constructor" <Endl;
}
~ Test ()
{
Cout <"destructor" <Endl;
}
Void fun1 (Test & T)
{
Cout <"fun1 called" <Endl;
}
Void fun2 (test T)
{
Cout <"fun2 called" <Endl;
}
};
Int main ()
{
Test T1;
Test T2 (T1 );
T2.fun2 (T2 );
T1.fun1 (T2 );
Return 0;
}
Execution result:
Default constructor
Fun2 called
Destructor
Fun1 called
Destructor
Destructor
Analysis of the above execution results, we can see that Program It explicitly creates two test class objects, but the default constructor executes only once, but the Destructor executes three times. The constructor can have multiple versions, but the Destructor has only one version: Is there a default version, or you can provide it yourself. Therefore, the program creates three test class objects. The execution result only calls one constructor because of the existence of the default copy constructor. What is the form of the default copy constructor? When was it called? What should I pay attention to during use? -- To be continued