3

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
{
    // ...
}

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I know this way, but I want to make whole Base interface public.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.