The other day I updated the contents of a cpp file containing assorted static data definitions to tighten up the const-ness of the assorted string; from
const char* to
char const * const. In doing so, In advertently converted a couple of structure definitions.
Now, I thought that the following kind of thing
1 2 3 4 5 6 7 8
|
struct Test
{
char const * const name;
};
const Test aTest[] = {
{"One", "Two", "Three", "Testing"}
};
|
was
not allowed!?
But both gcc and VC compile it, though VC does complain that it can't generate the required constructor and assignment operator.
My understanding was that:
1 - only POD struts could be used in aggregates (For those who haven't yet encountered the term: POD = "plain old data" = C struct, with no constructors, base classes, virtual methods)
2 - if a class/struct has a const or ref data member, these must be unitialized in the intializer list, which means there must be a constructor. Hence it is not POD.
So the constness here should mean that the struct is no longer a POD, and hence the aggregate is invalid.
Or is there another rule that come into play to allow this?
Andy