Goofy
Goofy

Reputation: 5397

Nested inheritance in C++

I've got question about nested inheritance in C++. I have three classes: Base, Middle and Top. Normally I use public inheritance when deriving from Middle, but I have one class (Top) which have inherit privately from Middle, however it should expose Base methods for public usage...

Here's my solution, is it ok?

class Base
{
    // ...
}

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

class Top :
    public virtual Base,
    private Middle
{
    // ...
}

Upvotes: 3

Views: 472

Answers (1)

Daniel Earwicker
Daniel Earwicker

Reputation: 116724

Suppose Base has a member function foo, you can put this in Top:

public:
    using foo;

The same for any other members you need to expose publicly.

Upvotes: 2

Related Questions