Reputation: 55
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?
Upvotes: 2
Views: 115
Reputation: 14434
Prior to C++11, you'd be correct: POD classes needed to be aggregate types, which in turn could not have private non-static data members. Post-C++11 however, POD types which are classes no longer need to be aggregates. Rather, POD types just need to satisfy the looser requirements of:
In C++20, std::is_pod
and the POD concept have been deprecated in favor of finer-grain properties and their tests, such as std::is_standard_layout
, std::is_trivial
, std::is_trivially_copyable
, and std::is_aggregate
.
Upvotes: 3