CLI 中的复制构造函数和赋值运算符
我正在尝试在 C++/CLI 中查找赋值运算符和复制构造函数的示例。我在谷歌上花了很多时间,令人惊讶的是我找不到一个看起来很常见的像样的例子。
I'm trying to locate examples of assignment operators and copy constructors in C++/CLI. I have spent a lot of time on Google and surprisingly I can't find a decent example of something that seems pretty common.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET 语义没有复制构造函数或赋值运算符之类的东西。您可以在
ref class
中定义一个,但它只会在C++端使用如果您显式请求副本`对于值类,一切都是内置的,您无法覆盖复制语义。示例:
如果您想以 .NET 风格实现深度复制语义,请查看
ICloneable
。另请参阅那里以获取您可以拥有的不同复制行为。不过,我强烈建议不要将
ref class
存储在堆栈上。.NET semantics have no such thing as a copy constructor or assignment operator. You can define one in your
ref class
es, but it will be used only in the C++ side if you request explicitly a copy` For value classes, everything is builtin and you cannot override copy semantics.Example:
Look at
ICloneable
if you want to implement deep copy semantics in the .NET style.Also look there to get the different copy behaviors you can have. I'd strongly advice against storing
ref class
es on the stack though.