tags:

views:

356

answers:

2

Consider:

class C {
private:
   class T {int a, b;};
};

C::T *p;

As expected, this produces a compilation error saying that C::T is private in the context of Line 6.

Now change this to pointer-to-member:

class C {
private:
   class T {int a, b;};
};

int C::T::*p;

This time around, gcc version 3.2.3 still makes the same complaint, but gcc version 3.4.3 lets it pass. Which is the correct behavior according to the standard?

+3  A: 

Since T is invisible from anywhere but the class C itself, I cannot imagine it would be allowed.

Tried this out on Comau, and he tells me the same. Sadly enough I don't know my way around the standard enough, so can't point you there.

xtofl
+3  A: 

To add to xtofl's post, see chapter 11 ([class.access]) of the standard:

A member of a class can be

private; that is, its name can be used only by members and friends of the class in which it is
declared.

protected; that is, its name can be used only by members and friends of the class in which it is declared, and by members and friends of classes derived from this class (see 11.5).

public; that is, its name can be used anywhere without access restriction.

Tritium