This one doesn’t want to compile:
class MainClass
{
public:
...
private:
class NestedClass
{ //Line 39
...
};
class NestedClass * getNestedClassFor(int i);
};
The compiler says:
error: ‘class MainClass::NestedClass’ is private
However, if I made NestedClass public, it would work.
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?
Thanks!
Update
Fixed the semi-columns. They’re not the problem. Neither is writing class in front of NestedClass.
Here’s the error message:
MainClass.h: In function ‘MainClass::NestedClass* getNestedClassFor(int i)’:
MainClass.h:39: error: ‘class MainClass::NestedClass’ is private
MainClass.cpp:49: error: within this context
Here’s the part of the .cpp file that’s also complaining:
class MainClass::NestedClass * getNestedClassFor(int i) //Line 49
{
return NULL;
}
Had forgotten to add the class scope in the .cpp, i.e.
Should be
Stupid me!