From what I know if a class is not an aggregate then it is sure not a POD.
However in the following code
#include <iostream>
#include <type_traits>
class NotAggregate2
{
int x; //x is private by default and non-static
};
int main()
{
std::cout << std::boolalpha;
std::cout << std::is_pod<NotAggregate2>::value << '\n';
std::cout << std::is_aggregate <NotAggregate2>::value << '\n';
}
which have output:
true
false
NotAggregate2 is not aggregate but a POD type.
So can a non-aggregate class be a POD class?
CodePudding user response:
Prior to C 11, you'd be correct: POD types needed to be aggregate types, which in turn could not have private non-static data members. Post-C 11 however, POD types no longer need to be aggregates. Rather, they just need to satisfy the looser requirement of being a standard layout type, which only requires that all non-static data members have the same access control, not necessarily public.