SOLVED!!!! c++ how do I nest a class?
So there is no way of doing it whereby it would be able to access them with m_Parent.m_Sprites rather than m_Parent->m_Sprites ?
Quote:Original post by darenking
So there is no way of doing it whereby it would be able to access them with m_Parent.m_Sprites rather than m_Parent->m_Sprites ?
Sure there is, use a reference.
class World { ... m_Sprites;public: //for example main() only class Loader;private: friend class Loader;};class World::Loader { World & m_Parent;public: Loader( World & Parent ) : m_Parent( Parent ) { } void Example () { m_Parent.m_Sprites = ...; ... & Sprites = m_Parent.m_Sprites; Sprites = ...; }};int main () { World MyLittlePlanet; World::Loader Loader( MyLittlePlanet ); Loader.Example();}
Quote:Original post by skjinedmjeet
What would the advantage of a nested class over a non-nested class be anyway?
Visual grouping and access control ( you can make a nested class private, and thus unusable outside of the class and it's friends itself ). Minor advantages, but on the flip side I can't think of any disadvantages to the practice.
Quote:Original post by darenking
One advantage is one fewer .h files.
I've got all this working now so thanks all!!!
You aren't required to have just one class in a header file. That's just a matter of preferance and grouping.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement