MC++ FAQ
Thursday 06 | 27 | 2002
'ref' arguments
How can I define a method that takes an 'ref' argument? If you want to define a method that takes a reference argument (that is, and in/out argument) that C# programs can see defined as "ref", you can use the C++ reference (&) syntax.

However, if the type of the argument is one of the basic types, and you try to use the C++ name for the type, this won't compile at first. For example, this won't work:

void MethodWithRef(int& v);

The simplest workaround is to use the CLR's typename, instead:

void MethodWithRef(System::Int32& v);
Posted by tomasr at June 27, 2002 01:09 AM
Comments

Arguably simpler, use the __gc modifier.
These two are equivalent.

void MethodWithRef1(System::Int32& v){
Console::WriteLine(S"Blah");
}

void MethodWithRef2(int __gc& v){
Console::WriteLine(S"Bleh");
}

Posted by: Adam on July 11, 2003 10:55 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?

Copyright(C) 2002, Tomas Restrepo, All rights reserved. Powered by Movable Type 2.63