I have a question concerning POD-ness. I expected that if B is non-POD and B is a member in A, so would A be non-POD. However the following code example outputs "10", hence B is correctly considered non-POD but A is.
struct A
{
int i;
struct B
{
std::string s;
};
};
std::cout << std::is_pod<A>::value;
std::cout << std::is_pod<A::B>::value;
Is this a bug in GCC? I'm using "c++ (GCC) 7.3.1 20180312". I don't see the sense in this behaviour. Lets say I wanted to optimize buffer allocations and use the POD-check in order to determine whether I would have to use new or can use malloc/realloc for a specific type. I would be totally wrong to use malloc to allocate storage for A. Best regards
A
has a type A::B
in it.
Instances of A
have no instance of A::B
in it. There is only a definition of the type, but no instantiation of it.
Add B b;
to A
and your anomaly goes away.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.