小编use*_*009的帖子

C++如何从具有不同返回类型的接口继承多个?

也许我有两个具有相同功能名称和参数的接口,但具有不同的返回值:

struct A { virtual void foo() = 0; };
struct B { virtual int foo() = 0; };
Run Code Online (Sandbox Code Playgroud)

如何定义继承此接口的类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 …
Run Code Online (Sandbox Code Playgroud)

c++ multiple-inheritance visual-studio-2012

8
推荐指数
1
解决办法
798
查看次数