Inherit from const class

后端 未结 8 1601
不思量自难忘°
不思量自难忘° 2021-01-12 00:24

I would like to inherit from a class with the const specifier like this:

class Property
{
    int get() const;
    void set(int a);
};

class Co         


        
8条回答
  •  天涯浪人
    2021-01-12 01:05

    Introduce mutability later in your inheritance tree and derive appropriately:

    class Property
    {
        int get() const;
    };
    class MutableProperty : public Property {
    {
        void set(int a);
    };
    

    And then:

    class ConstChild : public Property { ... };
    class MutableChild : public MutableProperty { ... };
    

提交回复
热议问题