7
#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。
对不起,我没有看到POD_Child作为POD_Child2的成员,我删除了答案,因为它是不正确的:) – 2013-02-19 16:39:21
[自2008年以来事情发生了变化(相当多)](http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods以及如何为什么是他们特别/ 7189821#7189821),而旧的编译器可能只是错了。 – 2013-02-19 16:47:43
我在VC2010中得到了与2008年相同的结果。 – user93353 2013-02-19 16:54:28