C++ POD

44 篇文章 1 订阅
17 篇文章 0 订阅

最近由于同事在代码中对于memset的滥用,导致了服务器一系列的问题。所以接触到了is_pod.在此顺便了解了一下POD.总结如下:


POD : 仅仅有Plain Old Data的类型就是POD类型.


Plain Old Data包括如下:


The actual definition of a POD type is recursive and gets a little gnarly. 
Here's a slightly simplified definition of POD: 
1. a POD type's non-static data members must be public 
2. and can be of any of these types: 
bool, 
any numeric type including the various char variants, 
any enumeration type, 
any data-pointer type (that is, any type convertible to void*), 
any pointer-to-function type, 
or any POD type, 
including arrays of any of these.
x. Note: data-pointers and pointers-to-function are okay, but pointers-to-member are not. Also note that references are not allowed. 这个对c++98的标准,TC1就修正了 
3. In addition, a POD type can't have constructors, virtual functions, base classes, or an overloaded assignment operator.


A POD is a type (including classes) where the C++ compiler guarantees that there will be no "magic" going on in the structure: for example hidden pointers to vtables, offsets that get applied to the address when it is cast to other types (at least if the target's POD too), constructors, or destructors. Roughly speaking, a type is a POD when the only things in it are built-in types and combinations of them. The result is something that "acts like" a C type.


没有用户声明的构造函数。


没有私有或受保护的非静态数据成员。


没有基类。


没有虚函数。


非静态数据成员不引用类型。


没有用户定义的复制赋值运算符。


没有用户定义的析构函数。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值