C ++ cow brush off questions day25

1. When an object is not used is usually built up copy constructor, after copying of the copy object is created using the assignment operator need overloaded.

The copy constructor form:

CExample (const CExample & C) is the copy constructor of our custom. Visible, copy constructor is a special constructor function , the function names and class name must be consistent, it must present a type of parameter is a reference variable .

Call occasions: when the parameter as a function of the object class; return value of the function is the object class; objects need to be initialized by another object.

Shallow copy when copying the default constructor, i.e., only the value of the new object simply be copied. The deep copy is required more complex operations simple assignment does not solve the problem. For example, A has int * p = new int (100).

When B is not simply assigned Bp = Ap should be re new operation in B. This is shades of difference.

Another point, the system can help us automatically shallow copy of such CLASS A (B). Such an operation. CLASS is not defined even if the copy constructor, we can still achieve their goals.

 

2. In the computer, represents characters, UTF-16 is two bytes, UTF-8 is three bytes. If saved as a text file, still need to be identified, UTF-16 occupies two bytes, UTF-8 occupies three bytes.

 

Guess you like

Origin www.cnblogs.com/Tonarinototoro/p/11600765.html