Nested Inheritance in C ++

I have a question about nested inheritance in C ++. I have three classes Base, Middleand Top. Usually I use public inheritance when creating Middle, but I have one class ( Top) that inherits privately from Middle, however it must disclose methods Basefor public use ...

Here is my solution, ok?

class Base
{
    // ...
}

class Middle :
    public virtual Base
{
    // ...
}

class Top :
    public virtual Base,
    private Middle
{
    // ...
}
+3
source share
1 answer

Assuming you Basehave a member function foo, you can put this in Top:

public:
    using foo;

The same goes for any other contributors you must publish publicly.

+2
source

Source: https://habr.com/ru/post/1784957/


All Articles