问题描述
我有一个用c ++ / cli编写的抽象基类。此类位于项目中。我还有其他继承抽象基类的项目。因此,结构如下所示。
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.
基础项目:
public ref class Base abstract
{
// implementation
virtual CommonFunc();
};
public delegate void Foo();
派生项目A:
public ref class A : public Base
{
// implementation
};
衍生项目B:
public ref class B : public Base
{
// implementation
};
等等。我可以在C#项目中同时调用A和B类。没问题。
And, so on. I can call both A and B classes on a C# project. No problem with that.
但是,当我尝试使用Base的Foo委托时,会收到如下错误:
However, when i try to use Foo delegate of Base, it gets an error like following;
这个。我在C#项目中为A和B的引用定义了extern别名。因此,当我使用AliasA.Foo之类的设备时,就可以了。但是,在两个A和B dll中存在两个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.
最后,当我尝试开发如下代码时,编译器不知道AliasBase.Base是A的基数。
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();
我希望我能说清楚。夏季我有三个dll。其中一个是基类的dll,其他是集成类的dll。继承的类的dll内部包含它们自己的基本实现。有没有办法摆脱基类的多个实现?
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?
注意:是的,如果我将它们收集到项目中,将没有问题。但是,我被要求为所有派生项提供单独的dll。
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.
预先感谢。
推荐答案
正如汉斯·帕森特(Hans Passant)在评论中所建议的那样,我摆脱了头文件,只使用了引用,最后继承成功了。我只需要在C#端为基类设置一个别名,并且它与父类具有继承关系。因此,以下代码现在可以正常工作。
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();
这篇关于clr项目dll之间的继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!