Is the following C++11 program ill-formed?
struct a
{
struct b { };
void f() {};
};
extern struct a b;
struct a ::b;
int main()
{
b.f();
}
Why / why not?
The thing of interest here is this line:
struct a ::b;
Is this a forward declaration of the inner class a::b
?
Or is this a definition of the global variable b
? Equivalent to:
struct a (::b);
struct a ::b;
doesn't declare a variable named b
of type a
, if that's what you are asking. It's a (redundant) forward declaration of the nested type a::b
. Whitespace is not generally significant in a C++ program. So your program declares, but never defines, a variable named b
. That's a violation of One Definition Rule: the program is therefore ill-formed, and the linker will tell you as much.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With