请问^符号代替C#的"参考"在通过在C ++ / CLI代码的参数? [英] Does the ^ symbol replace C#'s "ref" in parameter passing in C++/CLI code?

查看:138
本文介绍了请问^符号代替C#的"参考"在通过在C ++ / CLI代码的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,通过引用是:

In C#, passing by reference is:

void MyFunction(ref Dog dog)

但在C到目前为止,我已经看到了++ / CLI的代码示例,也没有用 REF的而是 ^ 符号用于:

But in C++/CLI code examples I have seen so far, there is no use of ref but instead ^ symbol is used:

void MyFunction(Dog ^ dog)

时使用的^ 符号直接替换 REF 参数传递的时候? ?还是有一些其他的意思我不知道的。

Is the use of ^ symbol a direct replacement for ref when parameter passing? or does it have some other meaning I'm not aware of?

另一个问题:我也看到了很多的:

Additional Question: I also see a lot of:

Dog ^ myDog = gcnew Dog();



它看起来像它的使用像 * (指针)在C ++中..它是否同样工作的?

It looks like it's used like * (pointer) in C++.. Does it work similarly?

谢谢!

推荐答案

如果是(在C#)的引用类型,然后在C ++ / CLI当量为:

If Dog is a reference type (class in C#) then the C++/CLI equivalent is:

void MyFunction(Dog^% dog)

如果是值类型(结构在C#),那么C ++ / CLI等效为:

If Dog is a value type (struct in C#) then the C++/CLI equivalent is:

void MyFunction(Dog% dog)

作为的型装饰 ^ 大致关联到 * 在C ++和大致关联到&放大器; 在C ++

As a type decorator, ^ roughly correlates to * in C++, and % roughly correlates to & in C++.

作为的单目运算符的,通常仍然需要使用 * 在C ++ / CLI在您使用 * 在C ++中,但您通常需要使用在C ++ / CLI在您使用 &安培; 在C ++

As a unary operator, you typically still need to use * in C++/CLI where you use * in C++, but you typically need to use % in C++/CLI where you use & in C++.

这篇关于请问^符号代替C#的"参考"在通过在C ++ / CLI代码的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆