I was trying to forward-declare nested type struct A::impl and run into this
issue.
The following code snippet compiles fine:
struct A {
struct impl; // `struct impl` fwd declaration
void f(impl); // A::f declaration
};
struct A::impl {}; // definition
void A::f(impl) {}
However, if I move the forward-declaration into the parameter list of member-function A::f, I get a compiler error:
struct A {
void f(struct impl); // A::f declaration and `struct impl` fwd declaration
};
struct A::impl {}; // compile-time error
//struct impl {}; // < This compiles, instead
void A::f(impl) {}
It looks like I'm forward-declaring struct impl instead of struct A::impl.
The compiler error is (on Clang 14.0.0):
error: no struct named 'impl' in 'A'
struct A::impl {};
Question: why is
struct A {
void f(struct impl);
};
different from
struct A {
struct impl;
void f(impl);
};
with respect to the scope of struct impl?