开发者

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

Let's say I have:

class A {

public:
    class B {

    };

};

Is there a开发者_StackOverflow中文版ny 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?


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.


There isn't any difference other than the scoping rules for "B". Clients that use "B" must qualify its scope with "A::". Nesting the "B" can sometimes be problematic when you want to forward reference it, since C++ compilers typically do not allow you to forward reference a class within a class (it does allow you to forward reference a class within a namespace though).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜