【问题标题】:Implement a class derived from an interface which derived from another interface实现从一个接口派生的类,该接口派生自另一个接口
【发布时间】:2017-04-12 00:30:14
【问题描述】:

我有以下接口和类

public interface IBase
{
    virtual void SomeBaseMethod()=0;
}

public interface IDerived : IBase
{
    virtual void SomeOtherMethod()=0;
}

public class base: public IBase
{
    void SomeBaseMethod(){};
}

public class derived: public base, public IDerived 
{
    void SomeBaseMethod(){};
    void SomeOtherMethod(){};
}

在派生类中,我必须重复“void SomeBaseMethod(){};”,这已经在我的类库中实现。否则我会得到编译错误。是否可以不重复'void SomeBaseMethod(){};'在我的类派生?

【问题讨论】:

标签: c++ com


【解决方案1】:

很遗憾,您必须在这里重复一遍。 C++ 有虚拟继承,可以解决这个问题,但是你不能对 COM 接口使用虚拟继承。 Here's an explanation as to why.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 2010-09-22
    • 2017-12-26
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多