Copyconstructor.cpp:Defines the entry point for the console application.
#include "stdafx.h"
class A
{public
:
A () {}
~a () {}
int v;
};
Class B
{public
:
B () {}
//b (b &b): A (B.A) {} //copy constructor for the composite copy constructor I
//b (b &b) c16/>//{
// a = B.A; Copy constructors corresponding to synthetic copy constructors II
//}
~b () {}
A;
};
int _tmain (int argc, _tchar* argv[])
{
b b;
B.A.V = 1;
B B0 = b;//Invoke composite copy constructor return
0;
}
Note:
//1. The composite copy constructor is the default copy constructor.
//2. The composite copy constructor is equivalent to an assignment to all member variables.
//3. Therefore, if a member's default assignment operation does not satisfy the requirement (if a linked list or contains pointers),
it is necessary to define the overloaded assignment operator for the member class to make the composite copy constructor work.
//4. Generally, for the underlying class, it is best to implement constructors, copy constructors, destructors,
and (note) overloaded assignment operators.