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

前端 未结 8 1125
醉酒成梦
醉酒成梦 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:00

    Have a look at this search. Diamond inheritance is somewhat of contentuous issue and the proper solution dependes on individual situation.

    I would like to comment on the Unix/Windows side of things. Generally one would #ifndef things out that are not appropriate for the particular platform. So you would end up with just Foobar compiled for either Windows or Unix using preprocessor directives, not UnixFoobar and WindowsFoobar. See how far you can get using that paradigm before exploring virtual inheritance.

提交回复
热议问题