friend class with limited access

后端 未结 3 1883
轮回少年
轮回少年 2020-11-30 02:41

I want to make a class A friend class of class B. I want to do this as these interact very much and A needs to change internals of class B (which I dont want to expose using

3条回答
  •  星月不相逢
    2020-11-30 03:11

    You can do following thing..

    class A{
    };
    
    class B{
    private: 
        void setFlags();
    protected:
        void setState();
    
    }; 
    
    class RestrictedB :public B{  
        friend class A;
    };
    

提交回复
热议问题