Problem with protected fields in base class in c++

后端 未结 2 1943
情深已故
情深已故 2021-01-12 23:03

I have a base class, say BassClass, with some fields, which I made them protected, and some pure virtual functions. Then the derived class, say DerivedCla

2条回答
  •  孤街浪徒
    2021-01-12 23:36

    This works:

    #include 
    
    struct Base {
    virtual void print () const = 0;
    protected:
    int val;
    };
    
    struct Derived : Base {
    void print () { std::cout << "Bases's val: " << val << std::endl; }
    };
    

提交回复
热议问题