jeudi 15 novembre 2018

prevent inheritance in c++

To avoid inheritance of class Base, I ran a test:

class non_inherit {
protected:
    non_inherit(){}
};

class Base : virtual non_inherit{
public:
    Base(){}
};

class Derived : public Base{
public:
    Derived(){}
};

int main(){
    Derived d;
    return 0;
}

And it runs successfully with no errors. Since Base is privately inherited from non_inherit, the default constructor is supposed to be private for Derived, so how can Derived access the constructor of non_inherit?

Aucun commentaire:

Enregistrer un commentaire