您能否派生出托管 C++ 来自非托管 C++ 的类 班级?
我有一个在非托管 dll 中编写的非托管 C++ 类。 我有一个引用非托管 dll 的托管 dll。 托管 dll 中的类可以从非托管类派生吗?
使用 Visual Studio 2008
I have an unmanged C++ class I have written in an unmanged dll. I have a managed dll that references the unmanaged dll. Can a class in the managed dll derive from the unmanaged class?
Using Visual Studio 2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能。 托管类的实例被垃圾收集并在 CLR 堆上创建。 非托管类的实例在非托管堆上分配。 如何能够创建一个对象,其数据部分位于托管堆上,而其基本数据位于非托管堆上?
您应该尝试其他技术,例如将托管容器包装在非托管事物上,反之亦然,并可能从中派生。
You can't. Instances of managed classes are garbage collected and created on the CLR heap. Instances of unmanaged classes are allocated on the unmanaged heap. How could you be able to create an object whose data is partially on the managed heap and its base data on the unmanaged heap?
You should try other techniques, e.g. wrap a managed container over the unmanaged thing or vice versa and derive from that, probably.
您还不能。还。 Herb Sutter 撰写了一篇内容广泛的 C++/CLI 设计原理,其中暗示了这样的事情也许有一天确实有可能。 不过,微软似乎已经停止了C++/CLI的进一步开发?
You can't yet. Herb Sutter wrote an extensive C++/CLI Design Rationale where he hints such things may indeed be possible one day. However, it seems that Microsoft has stopped further development of C++/CLI?
您能做的最好的事情就是将非托管类包装在管理器包装器中,然后从中派生。
The best you can do is wrap you unmanaged class in a manager wrapper and then derive from that.