Each class has only one destructor and one assignment function, but it can have multiple constructors (one copy constructor, others called ordinary constructors). For any class A, if you do not write the above functions, the C + + compiler will automatically generate four default functions for a, for example:
A (void);//Default parameterless constructor
A (const a&a);//Default copy constructor
~a ();//Default destructor
a&operator= (const A &a);//Default assignment constructor
1), "Default copy Constructor" and "Default Assignment function" are all implemented by "bit copy" rather than "value copy", and if the class contains pointer variables, these two functions are doomed to error.
2), when the class has not been generated, the call is a copy constructor, when the class has been generated, the call is an assignment constructor, as follows:
A;
A b;
b = a;//The Class A and B are now generated, so the assignment constructor is called
A C;
A d=c;//when Class D is not yet generated, the copy constructor is called
3), all function calls are arguments, the copy constructor is called. If a function argument uses a reference type, no copy of the argument will occur, and no function will be called.
As follows:
void Print_a (const a A);//Call copy constructor
void Print_b (const A &a);//For reference, no function is called
4), copy constructors and assignment constructors to implement.
A::A (const A&A)
{
}
The copy constructor is not returned as a completely new class.
A &a::operator= (const a&a)
{
return *this;
}
The assignment constructor returns itself, *this, as a large operation on the original class.
C + + Class four default function-constructor constructor copy constructor assignment constructor