-1

I have the following interfaces and classes

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(){};
}

In class derived, I have to repeat 'void SomeBaseMethod(){};', which have already implement in my class base. Otherwise I will get compile error. Is it possible not repeat 'void SomeBaseMethod(){};' in my class derived?

Jenny
  • 1
  • 2
    You have a [diamond inheritance](https://stackoverflow.com/questions/2659116/how-does-virtual-inheritance-solve-the-diamond-multiple-inheritance-ambiguit) problem. – Cory Kramer Apr 11 '17 at 15:48
  • 1
    Which version of C++ has the keyword `interface`. Looks more like Java. – Thomas Matthews Apr 11 '17 at 15:52
  • 1
    @ThomasMatthews It is not standard C++, but it is an [extension in Visual Studio](https://msdn.microsoft.com/en-us/library/737cydt1.aspx) (which I discourage using) – Cory Kramer Apr 11 '17 at 16:04

1 Answers1

0

Unfortunately, you have to repeat yourself here. C++ has virtual inheritance, which would solve this problem, but you can't use virtual inheritance with COM interfaces. Here's an explanation as to why.

Community
  • 1
  • 1
Michael Gunter
  • 12,528
  • 1
  • 24
  • 58