Original link: http://blog.csdn.net/bichenggui/article/details/4719363
A simple collation of the main content:
The first to see the type of pod (plain old data) is in imperfect C + +. I think this is a very important book that takes me to C + + world.
This explains the pod in this book:
1, all scalar types (basic type and pointer type), POD structure type, pod union type, and these types of arrays, const/volatile decorated version
This is all pod type.
2, POD structure/union type: An aggregation (including Class), its non-static members are not pointer to class member,
Pointer to class member function, non-POD structure, non-pod union, and these types of arrays, references, const/
volatile modified version;
Also, this aggregation cannot have user-defined constructors, destructors, and copy constructors.
3. Pod types can have static members, member TypeDef, nested STRUCT/CLASS definitions, and member functions/methods.
(c + + standard) the definition given:
Copies the bytes of an object into a byte array, and then copies it back into the storage area of the original object, at which point the object should have its original value.
Characteristics of POD types:
All pod types can be members of union, whereas all non-pod types cannot be members of union.
Pod Feature utilization:
We can use the pod type attribute to determine whether a type is a pod type:
Template<class t> struct Must_be_pod
{
Union
{
T Noname;
};
};
This template means that as long as the type T is a non pod type, the compiler will make an error, because T is a member of the Union.
The test code in VS2008 is as follows:
Class A
{
Public
A () {}
void F () {cout << "a::f" << Endl;}
Protected
Private
int i;
Int J;
};
Template<class t> struct Must_be_pod
{
Union
{
T Noname;
};
};
Must_be_pod<a> A; The compiler will complain: 1>member ' must_be_pod<t>::noname ' of Union ' must_be_pod<t>::<unnamed-tag> ' has User-defined constructor or Non-trivial default constructor
In fact, the nature of pod is a data type compatible with C.