private inheritance

后端 未结 6 458
清歌不尽
清歌不尽 2020-11-29 12:35

I dont completely understand this:

class Base
{
    public:
    Base()
    {
        cout<<\"Base\" << endl;
    }

    virtual void call()
    {         


        
6条回答
  •  难免孤独
    2020-11-29 12:59

    Because private means "implementation detail", which makes the fact that Derived derives from Base an implementation detail.

    Private inheritance is not interface inheritance, but implementation inheritance. It doesn't implement an "Is-A" relationship, but an "Is-Implemented-Using" relationship. Derived isn't a Base as far as users of the classes are concerned, it just happens to (currently) be implemented using it.

提交回复
热议问题