clr项目dll之间的继承

编程入门 行业动态 更新时间:2024-10-21 16:19:31
本文介绍了clr项目dll之间的继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个用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;

错误: Foo是 Foo和 Foo之间的不明确引用

Error : 'Foo' is an ambiguous reference between 'Foo' and 'Foo'

这个。我在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();

错误:无法将类型'A'隐式转换为'Base'

Error : Cannot implicitly convert type 'A' to 'Base'

我希望我能说清楚。夏季我有三个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之间的继承

本文发布于:2023-11-17 02:18:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608452.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   clr   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!