C++引用类型参数传递与C#引用之间的区别?

Anz*_*rio 2 c# c++

我一直以为他们是关于同样的事情,但有人在我的一个答案中指出了我并不是这样.

编辑:是我说的和我得到的评论.Edit2:C++之间的区别是什么:

public: void foo(int& bar);
Run Code Online (Sandbox Code Playgroud)

和C#的

public void foo(ref int bar){

} 
Run Code Online (Sandbox Code Playgroud)

Sma*_*ery 5

在C#中,您有原始类型(整数,结构等)和引用类型(对象).这些内置于语言中.在C++中,你必须是明确的.下面是一组在C#和C++中引用对象的等效方法,基于它们是引用类型还是基元,以及是否使用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 (&*)
Run Code Online (Sandbox Code Playgroud)