C ++引用类型的参数传递和C#的裁判之间的区别? [英] Difference between C++ reference type argument passing and C#'s ref?

查看:105
本文介绍了C ++引用类型的参数传递和C#的裁判之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直以为他们是同样的事情,但有人指出我没法回答,这种说法并不完全正确的一个



编辑:这里就是我说的,我得到的评论。
EDIT2:
什么是C ++的区别:

 市民:无效美孚(INT&安培;巴); 

和C#的

 公共无效美孚(REF INT吧){

}


解决方案

在C#中,有原始类型(整型,结构等)和引用类型(对象)。这些内置于语言。在C ++中,你必须要明确的。下面是一组,指的是在C#和C对象的等效方法++基于他们是否是引用类型或原语,以及是否你使用REF:

  C#类型| C ++类型
---------------------------- + ---------
为基本型,没有裁判|常规参数传递
引用类型,没有裁判|指针(*)
为基本型,与文献|参考(安培)
引用类型,与文献|一个指针引用(安培; *)


I always thought they were about the same thing but someone pointed me out in one of my answers that such ain't quite true.

Edit: Here is what I said and the comment I got. Edit2: What's the difference between C++'s:

public: void foo(int& bar);

and C#'s

public void foo(ref int bar){

}

解决方案

In C#, you have primitive types (ints, structs, etc.) and reference types (objects). These are built in to the language. In C++, you have to be explicit. Here is a set of equivalent ways of referring to objects in C# and C++, based on whether they are reference types or primitives, and whether or not you're using ref:

C# type                     | C++ Type
----------------------------+---------
Primitive type, with no ref | Normal parameter passing
Reference type, with no ref | Pointer (*)
Primitive type, with ref    | Reference (&)
Reference type, with ref    | Reference of a pointer (&*)

这篇关于C ++引用类型的参数传递和C#的裁判之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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