Inheritance between clr project dlls

五迷三道 提交于 2020-01-15 11:44:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!