POD数据

来源:互联网 发布:js防水涂料使用方法 编辑:程序博客网 时间:2024/05/20 18:42

A POD-struct is an aggregate class that has no non-static data members of type pointer to member, 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-union is an aggregate union that has no non-static data members of type pointer to member, 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.

POD结构(POD-struct)是一个聚合类,它没有以下类型的非静态数据成员:
指向成员的指针、非POD结构、非POD联合(或以上类型的数组),或它们的引用,
并且没有用户自定义的拷贝赋值运算符,也没有用户自定义的析构函数。
 
类似的,POD联合(POD-union)是一个聚合联合,
它没有以下类型的非静态数据成员:
指向成员的指针、非POD结构、非POD联合(或以上类型的数组),或它们的引用,
并且没有用户自定义的拷贝赋值运算符,也没有用户自定义的析构函数。

POD类(POD class)是一个类,它要么是POD结构,要么是POD联合。

以下几种是POD 
  
  1、所有基本数据类型 
  
  2、一个class或者struct,它不包含虚函数,没有虚基类,每一个数据成员都是POD,且所有的父类(如果存在的话)都是POD 
  
  3、POD数组 
  
  4、由POD组成的union 
  
  POD可以包含非虚成员函数,当然也可以包含构造函数和(非虚)析构函数,因为这些东东都不影响对象布局。 
  
 下面这个类,它不需要copy ctor就可以拷贝构造,但不是POD: 
  struct   S 
  { 
          std::string   str;    // std::string内部有指针,使用memcpy时执行浅拷贝 
  };  

原创粉丝点击