Friendship in nested classes C++
<p>I am trying to understand concept of friendship in nested classes but I am not getting the concept properly. I have written a sample program to understand it but the program is not working</p>

<pre><code>#include&lt;iostream&gt;

using namespace std;


class outerClass
{
    private:
        int a;
    public:
        class innerClass;
        bool print(innerClass);
};

class innerClass
{
    friend class outerClass;
    private:
        int b;

    public:
        innerClass() =default;

};

bool outerClass::print(outerClass::innerClass obj)
{
    cout&lt;&lt;"Value of b in inner class is:"&lt;&lt;obj.b;
}

int main()
{
    outerClass in;
    outerClass::innerClass obj;
    obj.b=5;
    in.print(obj);
}
</code></pre>

<p>I am getting below errors:</p>

<pre><code>try.cpp: In member function ‘bool outerClass::print(outerClass::innerClass)’:
try.cpp:26:6: error: ‘obj’ has incomplete type
try.cpp:11:15: error: forward declaration of ‘class outerClass::innerClass’
try.cpp: In function ‘int main()’:
try.cpp:34:28: error: aggregate ‘outerClass::innerClass obj’ has incomplete type and cannot be defined
</code></pre>

<p>As I read through articles on internet I learnt following points please comment on them if they are correct or not:</p>

<ul>
<li>innerClass can access all the members of outerClass by default.</li>
<li>For outerClass to access private members of innnerClass we need to make outerClass as friend class to innerClass.</li>
</ul>

<p>Please help in pointing out the mistake in code and also if the points I understood are correct.</p>