C + + POD type

Source: Internet
Author: User
Tags volatile

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.