问题
I have an abstract base class which is written with c++/cli. This class is located in a project. And i have other projects which inherit the abtract base class. So, the structure is like the following.
Base Project:
public ref class Base abstract
{
// implementation
virtual CommonFunc();
};
public delegate void Foo();
Derived Project A:
public ref class A : public Base
{
// implementation
};
Derived Project B:
public ref class B : public Base
{
// implementation
};
And, so on. I can call both A and B classes on a C# project. No problem with that.
However, when i try to use Foo delegate of Base, it gets an error like following;
Error : 'Foo' is an ambiguous reference between 'Foo' and 'Foo'
To get rid of this. I defined extern alias for references of A and B in the C# project. So, when i use like AliasA.Foo, it's ok. But, there exists two Foo's in two A and B dlls. That's a problem.
And at the end, when i try to develop some code like the following, the compiler doesn't know that the AliasBase.Base is base of A.
AliasBase.Base base = new A();
base.CommonFunc();
base = new B();
base.CommonFunc();
Error : Cannot implicitly convert type 'A' to 'Base'
I hope I made myself clear. To summerize; i have three dlls. One of them is base's dll and the others are inteherited class's dlls. The inherited class's dlls contains their own base implementation inside. Is there a way of get rid of multiple implemtantatins of the base class?
Note: Yes, if i collect them into a project, there will be no problem. But, i'm requested to deliver seperated dlls for all derived items.
Thanks in advance.
回答1:
As Hans Passant suggested on comment, i got rid of header files and used only references,at the end inheritence worked. I had to set only one alias for base class on C# side and it has an inheritance relationship with parant classes. So, the following codes are working now.
AliasBase.Base base = new A();
base.CommonFunc();
base = new B();
base.CommonFunc();
来源:https://stackoverflow.com/questions/47683677/inheritance-between-clr-project-dlls