Reputation: 33864
In the c++ draft standard we have this statement in [class.nest]:
2 Member functions and static data members of a nested class can be defined in a namespace scope enclosing the definition of their class. [Example:
struct enclose { struct inner { static int x; void f(int i); }; }; int enclose::inner::x = 1; void enclose::inner::f(int i) { /* ... */ }
—end example ]
My confusion is that if this is possible then why isn't the following possible:
struct enclose {
struct inner {
void f(int i);
};
void inner::f(int i) {}
};
error: cannot define member function 'enclose::inner::f' within 'enclose' void inner::f(int i) {}
Doesn't the definition of f
lie in the same scope enclosing the definition of the inner
class?
If not, then why is this not allowed? What issue is there with defining this function in the class scope?
Upvotes: 2
Views: 209
Reputation: 303147
The wording you cited says it can be defined in namespace scope. You're attempting to define it within struct enclose
, which is class scope, not namespace scope.
Upvotes: 2