C++ private function can’t access public nested class

  access-modifiers, c++, inner-classes

In the following code:

class Outer {
   private:
    void f_private(Outer::Inner in); // Wrong

   public:
    class Inner {};
    void f_public(Outer::Inner in); // OK
};

f_private() cannot use nested class Outer::Inner as parameter type. But it’s ok to do so in f_public(). Can someone explain to me what rule is this based on? And what’s the benefit of this rule?

Source: Windows Questions C++

LEAVE A COMMENT