Can't make a private method in C++ return a pointer to a private nested class
<p>This one doesn't want to compile:</p>

<pre><code>class MainClass
{
public:
    ...

private:
    class NestedClass
    { //Line 39
        ...
    };

    class NestedClass * getNestedClassFor(int i);
};
</code></pre>

<p>The compiler says:</p>

<blockquote>
  <p>error: 'class MainClass::NestedClass' is private</p>
</blockquote>

<p>However, if I made NestedClass <code>public</code>, it would work.</p>

<p>Why doesn't it work? It's not as though I'm exporting a nested class through a public method? It's just a private method returning a pointer to a private class. Any ideas?</p>

<p>Thanks!</p>

<h2>Update</h2>

<p>Fixed the semi-columns. They're not the problem. Neither is writing <code>class</code> in front of NestedClass.</p>

<p>Here's the error message:</p>

<blockquote>
  <p>MainClass.h: In function 'MainClass::NestedClass* getNestedClassFor(int i)':</p>
  
  <p>MainClass.h:39: error: 'class MainClass::NestedClass' is private</p>
  
  <p>MainClass.cpp:49: error: within this context</p>
</blockquote>

<p>Here's the part of the .cpp file that's also complaining:</p>

<pre><code>class MainClass::NestedClass * getNestedClassFor(int i) //Line 49
{
    return NULL;
}
</code></pre>
