什么是POD数据类型? |
您所在的位置:网站首页 › pod数据类型 › 什么是POD数据类型? |
原文链接:http://blog.csdn.net/kongkongkkk/article/details/77414410
*在之前的vector扩容问题源代码剖析中,发现源码中对数据类型进行了是否为POD类型的检查,这篇就看看什么是POD。。。→_→* 了解vector扩容问题请戳传送门——vector扩容问题源代码剖析 http://blog.csdn.net/kongkongkkk/article/details/77320794 详细POD定义说明请戳传送门——POD数据类型解释说明 http://en.cppreference.com/w/cpp/concept/PODType 详细is_pod函数定义说明请戳传送门——is_pod函数定义说明http://en.cppreference.com/w/cpp/types/is_pod POD,是Plain Old Data的缩写,普通旧数据类型,是C++中的一种数据类型概念* POD类型与C编程语言中使用的类型兼容,POD数据类型可以使用C库函数进行操作,也可以使用std::malloc创建,可以使用std::memmove等进行复制,并且可以使用C语言库直接进行二进制形式的数据交换 请注意,C++标准没有使用此名称定义命名的要求或概念。 这是由核心语言定义的类型类别。它被包括在这里作为概念,只是为了一致性。 POD数据类型的要求 a scalar type(标量类型) a class type (class or struct or union) that is(一个类类型(类、结构体或联合体)) 在C++11之前 an aggregate type(聚合类型) has no non-static members that are non-POD(没有非POD的非静态成员) has no members of reference type(没有参考类型的成员) has no user-defined copy constructor(没有用户定义的拷贝构造函数) has no user-defined destructor(没有用户定义的析构函数) C++11之后 a trivial type(破碎的类型) a standard layout type(标准布局类型) has no non-static members that are non-POD(没有非POD的非静态成员) an array of such type(POD类型的数组) C++中判断数据类型是否为POD的函数:is_pod(C++11) //since C++11 Defined in header template< class T > struct is_pod; 1234 如果T是PODType(“普通旧数据类型”),即简单和标准布局,则将成员常量值设置为true。 对于任何其他类型,值为false //输出为: //true //false //false #include #include struct A { int m; }; struct B { int m1; private: int m2; }; struct C { virtual void foo(); }; int main() { std::cout |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |