Using C++, how do I correctly inherit from the same base class twice?

前端 未结 8 1109
醉酒成梦
醉酒成梦 2020-12-29 10:35

This is our ideal inheritance hierarchy:

class Foobar;

class FoobarClient : Foobar;

class FoobarServer : Foobar;

class WindowsFoobar : Foobar;

class UnixF         


        
8条回答
  •  遥遥无期
    2020-12-29 11:01

    You can access the variable with the qualified class name, but I forget the exact syntax.

    However, this is one of the bad cases of using multiple inheritance that can cause you many difficulties. Chances are that you don't want to have things this way.

    It's much more likely you want to have foobar privately inherited, have each subclass own a foobar, have foobar be a pure virtual class, or have the derived class own the things it currently defines or even define foobar on its own.

提交回复
热议问题