J
John Harrison
Both gcc 3.3.1 and VC++ 7.1 compile the following code.
struct Outer
{
struct Inner
{
int f() { return c; }
};
private:
static const int c;
};
const int Outer::c = 123;
int main()
{
Outer::Inner o;
std::cout << o.f() << '\n';
}
Obviously I'm wrong but I thought the above breaks two different rules of
C++. Firstly isn't c private, secondly how can Inner access a member of
Outer without qualifying the name (i.e. return Outer::c)?
Explanations and references to the standard would be appreciated.
john
struct Outer
{
struct Inner
{
int f() { return c; }
};
private:
static const int c;
};
const int Outer::c = 123;
int main()
{
Outer::Inner o;
std::cout << o.f() << '\n';
}
Obviously I'm wrong but I thought the above breaks two different rules of
C++. Firstly isn't c private, secondly how can Inner access a member of
Outer without qualifying the name (i.e. return Outer::c)?
Explanations and references to the standard would be appreciated.
john