Reputation: 1305
What is the reason that the second class is not standard layout? (Visual Studio C++)
#include <iostream>
#include <type_traits>
struct A
{
int i;
};
struct B : public A
{
};
std::cout << "is_standard_layout<B> == "
<< std::boolalpha
<< std::is_standard_layout<B>::value // gives false
<< std::endl;
Upvotes: 2
Views: 1428
Reputation: 33425
Accorting to this MSVC supports built-in type traits since version 8 but this seems to say that you need version 11.
Section 9.7 defines a standard-layout class as a class that:
- has no non-static data members of type non-standard-layout class (or array of such types) or reference,
- has no virtual functions (10.3) and no virtual base classes (10.1),
- has the same access control (Clause 11) for all non-static data members,
- has no non-standard-layout base classes,
- 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, and
- has no base classes of the same type as the first non-static data member.
There's some explanation here.
Upvotes: 2