执行所有标准 C++功能在 C++/CLI 中工作吗?
如果我只在 C++/CLI 程序中包含现有的标准 C++ 类,它会起作用吗?
在我的测试中,一切都运行得很好,但是对于每个程序都是如此吗?
If I just include existing Standard C++ class in C++/CLI program, will it work?
In my tests everything worked pretty good, but is it true for every program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这就是微软的承诺。 (我观看了 这个视频昨天,他们在其中明确提到了这一点 - 特别是因为在 C++0x 中添加
nullptr
会损害它)所以是的,如果你采用本机C++ 程序并将其编译为 C++/CLI,没有代码更改,那么是的,它仍然可以工作。
当然,如果您更改代码(gcnew 而不是 new 和其他“托管”更改,那么当然,所有的赌注都会被取消,并且您可能会也可能不会破坏代码)
That is what Microsoft promises, yes. (I watched this video yesterday, in which they explicitly mentioned this -- specifically because the addition of
nullptr
in C++0x would compromise it)So yeah, if you take a native C++ program and compile it as C++/CLI, with no code changes, then yes, it will still work.
And of course, if you change your code (gcnew instead of new and other "managed" changes, then of course, all bets are off, and you might or might not break the code)
如果您实际上将该类更改为托管(gc)类,那么不行,它有时会中断。特别是,删除运算符的语义发生了变化,因为对象现在由垃圾收集器管理;删除对象可能不会释放任何内存。
If you actually change the class to be a managed (gc) class, then no, it will sometimes break. In particular, the semantics of the delete operator is changed, as the objects are now managed by the garbage collector; deleting an object might not release any memory.