I learned that default copy assignment operator (EDIT: corrected, not copy constructor) doesn't handle const and reference. Hence, if a class contains such members, then the compiler will not generate default copy constructor for it. Is this statement correct? Why const can not be handled?
Besides, if a class contains pointers as members, will the compiler generate a copy constructor? I understand default copy constructor only does shallow copy, but the compiler will at least generate a copy constructor, will it?
Thanks a lot for clarification!
If you do not define a copy constructor for a class
X
, a copy constructor is implicitly defined. It usually takes the formX(const X&)
, but it may also be have one of the other one-parameter forms if members require it, and it may be defined as deleted. The constructor behaves as if each member were initialized from the corresponding member of the right-hand side, and has an empty body. There are details, but that's the general idea.Since you can initialize const data members and reference data members from values of the same type, there is nothing special about such members. (The story is different for assignment, though.)