Is there any difference between a public nested class and a regular class?

 

Questions


Let’s say I have:

class A {

public:
    class B {

    };

};

Is there any difference between that public nested class and just a regular B class which is defined in its own cpp file, except for the fact that A::B must be used in the first option?

 

 

————————————————-

Answer

There is essentially no difference, except that A::B is a member of A, and so has all the access rights to private members of A that any other member would have.

c++,nested-class

Leave a Reply

Your email address will not be published. Required fields are marked *