Copy constructor
The problem solved by the copy constructor is: How to initialize the new object when an object is copied. Since the object is a complex data, it has complex behavior within compared with the built-in data type of the system. When an object is generated, how to initialize internal data is a critical problem, and the normal data type we can use simple assignment statements, such as int i = 0; and instances for a class need
Constructuring to complete the initialization. The problem now is how to initialize when an object is copied? An object is copied to have many ways, and it will be copied to the Function Frame when the object is directly copy, the object as the parameter of the function.
The following example:
Class HowMany2
{{
Public:
HOWMANY2 (const string & id = "")
{{
ObjectCount;
}
//
Copy Constructor: The following constructor will be called when the object is copied.
HOWMANY2 (Const HowMany2 & H)
{{
ObjectCount;
}
~ Howmany2 ()
{{
- ObjectCount;
}
Protaced:
Private:
Static int ObjectCount;
}