I tried to compile something like:
struct A
{ int a;
struct B
{ int c;
};
};
Now when I compile this code the compiler gives me a warning message that:
declaration does not declare anything [enabled by default]
I know that I have not defined any instance of struct B. That will mean that I shall not be able to access variable c. Still compiler compiles this code with a warning. What’s the whole point ? Why does not the compiler give a compilation error instead ?
ADDED Info:
The size of the struct A is equal to the size of int on my machine!!
Because you can do this:
Note:
B, which your code is missingA::B, but C doesn’t have the same scoping rules (all structs just belong to the global struct namespace, in effect)As to the motivation for allowing it …
Once you’ve allowed nested type declarations like this, I doubt there’s any particular motivation to require there be a member of that type right away.