#include <iostream>#include <new>#include <cstring>using namespace std;struct A { int a,b; char c;};struct A2 { short buf[1];};struct A3:A {};struct A4:A { short buf[1];};static_assert(std::is_pod<A>::value,"Struct must be a POD type");static_assert(std::is_pod<A2>::value,"Struct must be a POD type");static_assert(std::is_pod<A3>::value,"Struct must be a POD type");static_assert(std::is_pod<A4>::value,"Struct must be a POD type");int main(){}解决方法 它不是POD,因为它违反了标准布局类的规则:
— either has no non-static data members in the most derived class and
at most one base class with non-static data members,or has no base
classes with non-static data members
继承格中只有一个类可以有非静态数据成员.在这种情况下,两者都是A和A4有.
总结以上是内存溢出为你收集整理的c – 为什么这不是POD类型?全部内容,希望文章能够帮你解决c – 为什么这不是POD类型?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)