Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ref and out in C++/CLI

I know that the C++/CLI code

void foo(Bar^% x); 

transforms into

Void foo(ref Bar x); 

What is the C++/CLI code that becomes

Void foo(out Bar x); 

?

like image 477
Alexandre C. Avatar asked Aug 18 '10 16:08

Alexandre C.


People also ask

What is ref class in C#?

The ref keyword in C# is used for passing or returning references of values to or from Methods. Basically, it means that any change made to a value that is passed by reference will reflect this change since you are modifying the value at the address and not just the value.

What does Gcnew mean in C++?

ref new, gcnew (C++/CLI and C++/CX)The ref new aggregate keyword allocates an instance of a type that is garbage collected when the object becomes inaccessible, and that returns a handle (^) to the allocated object.

What is public ref class?

A ref class can contain public , protected , and private function members; only public and protected members are emitted into metadata. Nested classes and ref classes are permitted but cannot be public .

What is ref keyword in C++?

The ref keyword tells the compiler that the class or structure will be allocated on the heap and a reference to it will be passed to functions or stored in class members. The value keyword tells the compiler that all of the data in the class or structure is passed to functions or stored in members.


1 Answers

You can use the OutAttribute:

using namespace System::Runtime::InteropServices;     void foo([Out] Bar^% x);  
like image 87
Yochai Timmer Avatar answered Oct 07 '22 11:10

Yochai Timmer