1.1 c++的POD数据类型
POD: plain old data的缩写。
POD类型包括下面类型:
1、标量类型,c/c++的基本类型
- signed integer types (
signed char ,
short, int, long), - unsigned integer types (
unsigned char ,
unsigned short ,unsigned int ,
unsigned long ), - char and wchar_t, and
- bool.
- float, double, and
long double
- pointer-to-void (
void * ), - pointer-to-object and pointer-to-static-member-data (both of the form T* when pointing to an object of type
T), and - pointer-to-function and pointer-to-static-member-function (both of the form
T (*)(...) when pointing to a function that returns an object of type
T).
- pointer-to-nonstatic-member-data (of the form
T C::* when pointing to one of class
C's data members that has type T), and - pointer-to-nonstatic-member-functions (of the form
T (C::*)(...) when pointing to one of class
C 's member functions that returns an object of type
T).
2、用户自定义的类类型:
- non-static data (including arrays) of any pointer-to-member type,
- non-static data (including arrays) of any non-POD class type,
- non-static data of any reference type,
- user-defined copy assignment operator, nor
- user-defined destructor.
- user-declared constructors,
- private or protected non-static data members,
- base classes, nor
- virtual functions.
POD类型的c++特性:
1、布局
POD对象的内存字节是连续的。
2 初始化
1)如果定义一个非常量的POD对象,没有进行初始化,这个对象将会有一个不确定的初始值。
2)POD类型的缺省初始化是0初始化。
3)如果对一个静态的POD对象进行初始化,
如果是局部静态对象,那么初始值是在第一次执行初始化语句块的时候设定如果是全局静态对象,那么初始值是在任何动态初始化之前设定。
3 拷贝
POD类型的对象可以copy
4 Addressing
The address of a POD object can be an address constant expression (or part of one) [§5.19, ¶4], while a reference to a POD member can be a reference constant expression 。
"A pointer to a POD-struct object, suitably converted using a reinterpret_cast, points to its initial member ... and vice versa"