C ++接口具有相同方法的多重继承

时间:2011-04-26 13:20:53

标签: c++ interface multiple-inheritance

我需要从两个接口继承,这两个接口都具有相同的方法,在两种情况下都应该执行完全相同的操作。这段代码是否正确?我需要这种代理类。谢谢你的回答。

class InnerInterface {
    virtual int getID() const = 0;
    //...
};
class OuterInterface {
    virtual int getID() const = 0;
    //...
};
class Foo : public InnerInterface, public OuterInterface {
    virtual int getID() const;
    //all abstract methods
};

1 个答案:

答案 0 :(得分:8)

是的,这是正确的。单个getID()方法可以覆盖两个虚方法。