I was trying to do this,
class Outer {
public:
struct inner_t {
void foo()
{
printf("%d", _x);
}
};
int _x;
};
int main()
{
Outer o;
o._x = 10;
}
The above can’t compile with errors:
error: invalid use of non-static data member ‘Outer::_x’
But according to this post, inner_t can indeed access Outer::_x, what’s wrong?
The problem is:
inner_tdoes not know an instance ofOuterto read_xfrom.If you had written (for example):
Or if
_xwas a static member ofOuter.Then it should work (at least it will give no error).