也许我有两个具有相同函数名称和参数但返回值不同的接口:
struct A { virtual void foo() = 0; };
struct B { virtual int foo() = 0; };
如何定义继承此接口的 C 类(如果可能的话)?例如,我编写了一些未编译的伪代码:
// this code is fake, it doesn't compiled!!
struct C : A, B
{
// how to tell compiler what method using if referenced from C?
using void foo(); // incorrect in VS 2012
// and override A::foo() and B::foo()?
virtual void foo() { std::cout << "void C::foo();\n"; } // incorrect
virtual int foo() { std::cout << "int C::foo();\n"; return 0; } // incorrect
}
// ... for use in code
C c;
A &a = c;
B &b = c;
c.foo(); // call void C::foo() when reference from C instance
a.foo(); // call void C::foo() when reference from A instance
b.foo(); // call int C::foo() when reference from B instance