“struct”和“value struct”之间的区别(Difference between “struct” and “value struct”)

编程入门 行业动态 更新时间:2024-10-21 13:31:56
“struct”和“value struct”之间的区别(Difference between “struct” and “value struct”)

有什么区别

public struct X{ public: int A;};

public value struct X{ public: int A;};

如何将一个转换为另一个?

What is the difference between

public struct X{ public: int A;};

and

public value struct X{ public: int A;};

How can I convert one into the other?

最满意答案

第一个是普通的C ++结构。

使用value struct创建C ++ / CLI值类型(.NET结构)。 您通常希望手动从一个副本复制到另一个,但如果内存布局相同,您通常可以使用Marshal::PtrToStructure类的东西直接复制数据。 请注意,这会返回一个盒装value struct ,但是,手动复制通常更有效。

The first is a normal C++ structure.

Using value struct creates a C++/CLI value type (a .NET structure). You typically will want to copy from one to the other manually, though if the memory layout is the same, you can often use things like Marshal::PtrToStructure to copy the data directly. Note that this returns a boxed value struct, however, so manual copying is often more efficient.

更多推荐

本文发布于:2023-08-05 20:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1438015.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:区别   struct   Difference

发布评论

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

>www.elefans.com

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