c – Visual Studio 2008中的POD

以下代码
#include <iostream>
#include <new>
#include <cstring>
#include <type_traits>

template<typename T>
void is_pod(char* c)
{
    cout << "Type " << c;
    if(std::is_pod<T>::value)
        ::std::cout << " is POD" << endl;
    else
        ::std::cout << " is not!" << endl;
}

#define CHECK_TYPE(ty) ::is_pod<ty>(#ty)

struct POD_Parent{};
struct POD_Child : public POD_Parent{int y;};
struct POD_Child2 {int x; POD_Parent y; POD_Child ssd;};

int main()
{
    CHECK_TYPE(POD_Parent);
    CHECK_TYPE(POD_Child);
    CHECK_TYPE(POD_Child2);

给出以下结果:哪个很奇怪!

Type POD_Parent is POD
Type POD_Child is not!
Type POD_Child2 is POD

POD_Child怎么不是POD?!和POD_Child2是POD?!!

请注意,我使用MinGW编译它(使用选项-std = c 11)并且它说所有这些都是POD.

解决方法

根据[MSDN] [1],具有基类的类型不是POD所以POD_Child不是POD但是对于POD_Child2它可能是编译器忽略ssd基类的一些错误

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...