多重継承を使用して C++ でダイアグラムを表現する良い方法は何ですか? または、この場合、多重継承を使用する必要がありますか? 基本クラスで Child1 と Child2 のインスタンスを作成して使用することはできませんか?
2 に答える
0
「基本クラスにChild1インスタンスとChild2インスタンスを作成して使用することはできませんか?」
あなたが達成しようとしているのはこれだと思います。多重継承は必要ありません。
class IChildInterface {}
class Base { IChildInterface* child; }
class Child1: public IChildInterface
class Child2: public IChildInterface
于 2012-04-12T08:08:51.120 に答える
0
これは疑似コードですが、階層を示す必要があります。
解決策 1:
class IBaseInterface {}
class Base : IBaseInterface {}
class Child1 : Base {}
class Child2 : Base {}
解決策 2:
class IChildInterface {}
class Base {}
class Child1 : Base, IChildInterface {}
class Child2 : Base, IChildInterface {}
于 2012-04-12T07:35:45.130 に答える