您能否派生出托管 C++ 来自非托管 C++ 的类 班级?

发布于 2024-07-12 19:43:56 字数 115 浏览 5 评论 0原文

我有一个在非托管 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沒落の蓅哖 2024-07-19 19:43:56

你不能。 托管类的实例被垃圾收集并在 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.

南烟 2024-07-19 19:43:56

您还不能。。 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?

最初的梦 2024-07-19 19:43:56

您能做的最好的事情就是将非托管类包装在管理器包装器中,然后从中派生。

The best you can do is wrap you unmanaged class in a manager wrapper and then derive from that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文