The following is invalid code:
struct foo {
struct bar;
bar x; // error: field x has incomplete type
struct bar{ int value{42}; };
};
int mai
I think this example is explicitly allowed by
17.6.1.2 Member classes of class templates [temp.mem.class]
1 A member class of a class template may be defined outside the class template definition in which it is declared. [Note: The member class must be defined before its first use that requires an instantiation (17.8.1) For example,
template
struct A { class B; }; A ::B* b1; // OK: requires A to be defined but not A::B template class A ::B { }; A ::B b2; // OK: requires A::B to be defined —end note ]
This should work fine too:
template
struct foo_impl {
struct bar;
bar x; // no problems here
};
template
struct foo_impl::bar{ int value{42}; };
using foo = foo_impl<>;
int main()
{
return foo{}.x.value;
}