TITLE: Friends and nested classes and enums PROBLEM: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott) Given the following class: class Outer { private: enum PrivateEnum { Foo, Bar }; friend class Inner; class Inner { public: Inner(int i= Foo) : myInt(i) {} // error here Inner() : myInt(Foo) {} // this also is an error private: int myInt; }; }; Why is it that Outer::Foo is not accessible to the constructor of Outer::Inner, given that it is forward-declared as a friend class? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 7 Feb 95 The problem is that the friend declaration does not declare Outer::Inner to be a friend, because that name isn't visible yet. It declares a hypothetical file-scope Inner to be a friend. To make Outer::Inner a friend, you either have to move the friend declaration after the Inner class definition, or add a forward nested declaration for Inner. The language rules were previously vague on this point, but a recent clarification of those rules by the C++ Committee allows this: class Outer { class Inner; // forward declare Outer::Inner friend class Inner; // make it a friend class Inner { ... }; }; It may be that your compiler doesn't follow the rule clarification yet, in which case you have yet another workaround: class Outer { enum PrivateEnum { Foo, Bar }; class Inner { Inner(int); // can't specify a default parameter yet int x; }; friend class Inner; public: Outer(); }; Outer::Inner::Inner(int i = Foo) : ... // now we can specify the default { ... }