"Effective C + +" read Note 01
size_t is an unsigned (unsigned) type used when calculating the number of C + +. It is also a parameter type accepted by the operator[] function in Vector,deque and string.
Define the declarative and the definition, for the object, the definition is the place where the compiler is allocating memory for this object, and for function or function template, the definition provides the code itself.
The default constructor either has no arguments, or each parameter has a default value.
class B { public: explicitB(int0booltrue//这也是一个default构造函数 }
Constructors that are declared as explicit can prevent them from being used to perform implicit type conversions, but can still perform display type conversions.
void dosomething(B object) {...}B oboj1;dosomething(bobj1); //ok,因为dosomething接受的是一个B类型的对象dosomething(28); //错误,dosomething接受一个B类型的对象,不是一个int, 而int和B之间没有隐式转换dosomething(B(28)); //ok,用B的构造函数将int显式转换为B类型
Because we generally do not want the compiler to perform unintended type conversions, we encourage the constructor to be declared as explicit
Copy constructor and copy assignment operator
class A {public: A(); A(const// copy构造函数 operator= (const//copy assignment操作符 //调用copy构造函数//调用copy assignment操作符
The copy constructor is used when constructing a new object, instead of the normal assignment when constructing a new object, the copy assignment operator is called.
The copy constructor is very important for the way Pass-by-value is passed. Consider
void func(A a) {...}A a1;func(a1);
The object of type a here is Pass-by-value, so A1 is copied in, so a temporary a object is constructed, and the temporary a object is done with the copy constructor.
for custom types, however, pass-by-reference is a better choice .
C + + Digest of effective C + +--1