Accessing protected members in a derived class

前端 未结 8 2033
礼貌的吻别
礼貌的吻别 2020-11-22 11:30

I ran into an error yesterday and, while it\'s easy to get around, I wanted to make sure that I\'m understanding C++ right.

I have a base class with a protected memb

8条回答
  •  花落未央
    2020-11-22 11:59

    Following the hack for stl I wrote a small code which seems to solve the problem of accessing the protected members in derived class

    #include 
    
    class B
    {
    protected:
        int a;
    public:
        void dosmth()
        {
            a = 4;
        }
    
        void print() {std::cout<<"a="<

    Prints

    a=4
    a=5
    

提交回复
热议问题