# 不小心翻阅到的一段关于POD的资料，总结记录在案

573人阅读 评论(0)

...A POD-struct is an aggregate class that has no non-static data members of type non-POD-struct,

non-POD-union (or array of such types) or reference, and has no user-defined copy assignment operator

and no user-defined destructor. Similarly, a POD-union is an aggregate union that has no non-static data

members of type non-POD-struct, non-POD-union (or array of such types) or reference, and has no user-

defined copy assignment operator and no user-defined destructor. A POD class is a class that is either a

POD-struct or a POD-union.

(我连换行什么的格式都一并拷贝了下来)

http://en.wikipedia.org/wiki/Plain_Old_Data_Structures

(A POD type in C++ is defined as either a scalar type or a POD class. A POD class has no user-defined copy assignment operator, no user-defined destructor, and no non-static data members that are not themselves PODs.)Moreover, a POD class must be an aggregate, meaning it has no user-declared constructors, no private nor protected non-static data, no bases and no virtual functions.

1.ISO标准中的要求.

2.没有虚函数和自定义的任何构造函数. ISO标准只禁止了重载operator "="和析构函数.

3.没有基类.

4.没有非静态的常量和引用类型成员. 这2个玩意儿没有自定义构造函数没法初始化.

5.无虚函数和自定义的任何构造函数的空类是非POD, 继承空类不会影响子类是否是POD的判断. 空类被打成非POD我怀疑仅是为了允许参数传递和返回值优化.

C++ 0x标准草案最新POD定义(好像已经投票通过了):

http://en.wikipedia.org/wiki/C%2B%2B0x

A class/struct is considered a POD if it is trivialstandard-layout, and if all of its non-static members are PODs.

A trivial class or struct is defined as one that:

1. Has a trivial default constructor. This may use the default constructor syntax (SomeConstructor() = default;).
2. Has a trivial copy constructor, which may use the default syntax.
3. Has a trivial copy assignment operator, which may use the default syntax.
4. Has a trivial destructor, which must not be virtual.

A standard-layout class or struct is defined as one that:

1. Has only non-static data members that are of standard-layout type
2. Has the same access control (public, private, protected) for all non-static data members
3. Has no virtual functions
4. Has no virtual base classes
5. Has only base classes that are of standard-layout type
6. Has no base classes of the same type as the first defined non-static data member
7. Either has no base classes with non-static data members, or has no non-static data members in the most derived class and at most one base class with non-static data members. In essence, there may be only one class in this class's hierarchy that has non-static data members.

1. 极简的默认建构式。这可以使用默认建构式语法，例如SomeConstructor() = default;
2. 极简的复制建构式，可使用默认语法（default syntax）
3. 极简的赋值操作符，可使用默认语法（default syntax）
4. 极简的解构式，不可以是虚拟的（virtual）

1. 只有非静态的（non-static）数据成员，且这些成员也是符合标准布局的类型
2. 对所有non-static成员有相同的访问控制（public, private, protected）
3. 没有虚函数
4. 没有虚拟基类
5. 只有符合标准布局的基类
6. 没有和第一个定义的non-static成员相同类型的基类
7. 若非没有带有non-static成员的基类，就是最底层（继承最末位）的类没有non-static数据成员而且至多一个带有non-static成员的基类。基本上，在该类的继承体系中只会有一个类带有non-static成员
个人观点, 仅供参考. 欢迎达人指点.
------------------------------------------------补正----------------------------------------------------------------

...A POD-struct is an aggregate class that：经过高人指点，标准中这句话的"that"使用不当，应当替换为"and"!

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：46087次
• 积分：946
• 等级：
• 排名：千里之外
• 原创：40篇
• 转载：1篇
• 译文：0篇
• 评论：28条
文章分类
• 1(1)
评论排行
最新评论