C++/CLI Object^%(脱字符百分号)声明是什么意思?

发布于 2024-10-18 06:03:41 字数 97 浏览 3 评论 0原文

这显然是一个谷歌验证的术语,因为我无法让任何搜索引擎不丢弃“额外”字符。我也查看了 MSDN 中的 C++ 参考,但我似乎找不到 C++/CLI 参考,因为声明部分中没有任何内容。

This apparently is a Google-proof term since I can't get any search engines to not throw away the "extra" characters. I did also look on MSDN in the C++ reference but I can't seem to find the C++/CLI reference because there is nothing in the declarations section on it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

吖咩 2024-10-25 06:03:41

%跟踪参考

它类似于本机引用 (Object&),但跟踪引用可以引用 CLR 对象,而本机引用则不能。这种区别是必要的,因为垃圾收集器可以移动 CLR 对象,因此 CLR 对象的内存地址可能会改变。

^句柄。这仅仅意味着它受到管理。请参阅 MSDN 以及这篇 SO 帖子

% is a tracking reference.

It is similar to a native reference (Object&), but a tracking reference can reference a CLR object while a native reference cannot. The distinction is necessary because the garbage collector can move CLR objects around, so a CLR-object's memory address may change.

The ^ is a handle. This simply means it is managed. See MSDN and also this SO post.

柏拉图鍀咏恒 2024-10-25 06:03:41

它的意思是“通过引用传递”:

 void bar::foo(Object^% arg) {
    arg = gcnew Object;    // Callers argument gets updated
 }

中的情况相同

 void foo(Object** arg) {
    *arg = new Object;
 }

C++或 C#

 void foo(out object arg) {
     arg = new Object();
 }

: C++/CLI 不区分 refout,它没有 C# 语言具有明确赋值检查功能,因此无需区分两者。 VB.NET 中的情况相同,ByRef 与 ByVal。

It means "pass by reference":

 void bar::foo(Object^% arg) {
    arg = gcnew Object;    // Callers argument gets updated
 }

Same thing in C++:

 void foo(Object** arg) {
    *arg = new Object;
 }

or C#:

 void foo(out object arg) {
     arg = new Object();
 }

C++/CLI doesn't distinguish between ref and out, it does not have the definite assignment checking feature that the C# language has so no need to distinguish between the two. Same in VB.NET, ByRef vs ByVal.

深海夜未眠 2024-10-25 06:03:41

本质上,它是 Object*& 的“托管”版本,相当于 C# 中引用类型的 refout

Essentially, it's the "managed" version of Object*&, and equivalent to ref or out on a reference type in C#.

番薯 2024-10-25 06:03:41

这是一个通过引用管理的指针。所以如果你有类似的东西:

void DoSomething(System::String^% stringObject)

在 C# 中它看起来像:

void DoSomething(ref System.String stringObject)

This is a managed pointer by reference. So if you had something like:

void DoSomething(System::String^% stringObject)

in C# it would look like:

void DoSomething(ref System.String stringObject)
甚是思念 2024-10-25 06:03:41

这是 C++/CLI 跟踪参考。这有点像 C++ 引用,但指向托管对象。

This is a C++/CLI Tracking Reference. This is kind of like a C++ reference, but to a managed object.

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