SOLVED!!!! c++ how do I nest a class?

Started by
14 comments, last by Erzengeldeslichtes 18 years, 7 months ago
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 ?
Advertisement
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();}
What would the advantage of a nested class over a non-nested class be anyway?
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.
One advantage is one fewer .h files.

I've got all this working now so thanks all!!!
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.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?

This topic is closed to new replies.

Advertisement