最近由于同事在代码中对于memset的滥用,导致了服务器一系列的问题。所以接触到了is_pod.在此顺便了解了一下POD.总结如下:
POD : 仅仅有Plain Old Data的类型就是POD类型.
Plain Old Data包括如下:
The actual definition of a POD type is recursive and gets a little gnarly.
Here's a slightly simplified definition of POD:
1. a POD type's non-static data members must be public
2. and can be of any of these types:
bool,
any numeric type including the various char variants,
any enumeration type,
any data-pointer type (that is, any type convertible to void*),
any pointer-to-function type,
or any POD type,
including arrays of any of these.
x. Note: data-pointers and pointers-to-function are okay, but pointers-to-member are not. Also note that references are not allowed. 这个对c++98的标准,TC1就修正了
3. In addition, a POD type can't have constructors, virtual functions, base classes, or an overloaded assignment operator.
A POD is a type (including classes) where the C++ compiler guarantees that there will be no "magic" going on in the structure: for example hidden pointers to vtables, offsets that get applied to the address when it is cast to other types (at least if the target's POD too), constructors, or destructors. Roughly speaking, a type is a POD when the only things in it are built-in types and combinations of them. The result is something that "acts like" a C type.
没有用户声明的构造函数。
没有私有或受保护的非静态数据成员。
没有基类。
没有虚函数。
非静态数据成员不引用类型。
没有用户定义的复制赋值运算符。
没有用户定义的析构函数。