TITLE: Using private nested classes PROBLEM: francis@parker.EECS.Berkeley.EDU (Francis Chang) I have a class: class Container { public: ... private: class Item { public: ... }; Item *foo(); void bar(Item *); ... }; Appended: Item *foo() { .... } I am getting a parse error before '*' in the definition of foo. Apparently, the compiler does not recognize the class 'Item'. Do I need to specify "Container::Item *" as the return value? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage) Yes, and also the name of foo as Container::foo, but it still won't work. Type Item is private to class Container, meaning only members or friends of Container may access the type. If function foo really needs to return an Item, it must be defined inline in the class definition. This restriction makes private types less useful than you might like. You can get around the restriction by having foo take a reference to an Item* as a parameter: class Container { public: ... private: class Item { ... }; void foo(Item*&); }; void Container::foo(Item*& I) { I = new Item; // for example } This function is equivalent (except for syntax and legality) to Container::Item* Container::foo() { return new Item; } The difference is that type Container::Item no longer appears at file scope, but only inside the scope of a member of class Containter. Function foo can be called only from a member or friend of Container, since you otherwise cannot use type Container::Item.