# Include <iostream>
Using namespace STD;
Class C
{
Public:
C () {cout <"chuangjiang C" <Endl ;}
C (const C & Other) {cout <"Coping C" <Endl ;}
C & operator = (const C & Other) {cout <"= C" <Endl ;}
};
Class B
{
Public:
B () {cout <"chuangjiang B" <Endl ;}
B (const B & Other) {cout <"Coping B" <Endl ;}
B & operator = (const B & Other) {cout <"= B" <Endl ;}
Int B;
};
Class
{
Public:
A () {cout <"chuangjinag a" <Endl ;}
A (const B & other): BB (other) {cout <"chuangjinag A with B" <Endl ;}
A (int I): B (I) {cout <"chuangjian A with int" <Endl ;}
A (const A & Other) {cout <"Coping a" <Endl ;}
A & operator = (const A & Other) {cout <"= A" <Endl ;}
Int B;
C cc;
B BB;
Void usestatic (){
Static B;
Cout <B. B <Endl;
}
};
A & getrefence (A & ){
Return;
}
A getvalue (A & ){
Return A; // return A ();
}
Int main (){
// Non-static member variables are first initialized and then run the constructor,
A aa (2 );
Cout <& aa <Endl;
// Difference between the return value and the return reference
A bb;
Cout <"difference between return value and return reference:" <Endl;
BB = getvalue (AA );
Cout <& BB <Endl;
BB = getrefence (AA );
Cout <& BB <Endl;
// Reference variables. The variables declared in Java are basically referenced variables.
Cout <"reference variable:" <Endl;
A & CC = getrefence (AA );
Cout <cc. B <"end" <Endl;
// Test when the initialization table is executed. You can change the CC and BB positions for the test.
// The result shows that initialization is performed based on the position of the member variables from top to bottom, whether or not in the initialization table
B;
Cout <"Create a with B:" <Endl;
A AB (B );
// A c = A (1 );
// A d [2] = {A (1), a (1 )};
// A * E = new A [2];
// Cout <E [1]. B <Endl;
// Test the local static variable
Cout <Endl <"test usestatic:" <Endl;
AA. usestatic ();
AA. usestatic ();
Cout <"sizeof B:" <sizeof (B) <Endl;
Cout <"sizeof A:" <sizeof (a) <Endl;
System ("pause ");
}
I tested the constructor and did not test the destructor.