Hi All,

Private data in a class can only be accessed by getter functions. If I have a class as the private data in another class, in another class...Example:

class Top
{
private:
    class Middle
    {
    private:
        class Bottom
        {
        private:
            int number;
        }   
    }
}

If I want to access the int number, I would call 3 getter functions. Is there a better way to do this other than reconstructuring? Sorry if this is too 'beginner'...

Also any good reads on nested classes are welcome. Thanks

Make the access for all of the class members public in the nested class and declare the nested class in the private part of the main class. this way you can access the members directly but only from within a function of the main class. If you don't want the nested class data to be public you could make it private and make the main class a friend of the nested class to get direct access.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.