C++ nested classes accessibility

前端 未结 4 693
清酒与你
清酒与你 2020-12-05 10:24

Given the following code without considering friendship between two classes:

class OutSideClass
{
...
public:
    int i_pub;
protected:
             


        
4条回答
  •  悲&欢浪女
    2020-12-05 10:29

    As @Nawaz points out, in C++03 nested classes do not have special access rights to members of the enclosing class. However, this limitation is easy to get around by declaring the nested class as a friend.

    class OutSideClass
    {
    ...
    
        class InSideClass
        {
            ...
        };
        friend class InSideClass;
    };
    

提交回复
热议问题