I have a class and a const variable.
struct A
{
int b;
};
A const a;
The class A is POD and can be initialized like this.
A const a = { 3 };
IMHO, it looks fine to have a constructor like this.
struct A
{
int b;
A(int newB) : b(newB)
{
}
};
But Clang assumes A as non-aggregate type. Why I can’t have constructor like that? Or should I do something else?
I modified question to present my original meaning. I had wrote the struct as class by mistake, and sorry for @Johannes about confusing 🙂
PODmeans Plain Old Data type which by definition cannot have user-defined constructor.POD is actually an aggregate type (see the next quotation). So what is aggregate? The C++ Standard says in section §8.5.1/1,
And section §9/4 from the C++ Standard says,
From this, its also clear that POD class/struct/union though cannot have user-defined assignment operator and user-defined destructor also.
There are however other types of POD. The section §3.9/10 says,
Read this FAQ : What is a “POD type”?