興味深い多重継承の問題を理解しようとしています。
祖父母は、複数のメソッドを持つインターフェイス クラスです。
class A
{
public:
virtual int foo() = 0;
virtual int bar() = 0;
};
次に、このインターフェースを部分的に完成させる抽象クラスがあります。
class B : public A
{
public:
int foo() { return 0;}
};
class C : public A
{
public:
int bar() { return 1;}
};
私が使用したいクラスは、両方の親から継承し、ディレクティブを使用して、どのメソッドがどこから来る必要があるかを指定します。
class D : public B, public C
{
public:
using B::foo;
using C::bar;
};
DI をインスタンス化しようとすると、抽象クラスをインスタンス化しようとするとエラーが発生します。
int main()
{
D d; //<-- Error cannot instantiate abstract class.
int test = d.foo();
int test2 = d.bar();
return 0;
}
誰かが問題を理解し、部分的な実装を最大限に活用する方法を教えてもらえますか?