mc++ and pass by reference

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I am very new to the MC++ 2005 visual studio world, and I was wondering how
you do pass by reference under the .Net syntax of mc++

(ie:) To do it in the C# version you would do something like this.
void myFuncA(ref string myValue)
{
myValue = "test";
}

(ie:) I tried to do something similar in MC++, but it doesn't show up right
under
the C# applications.
void myFuncA(System::String^ & myValue)
{
myValue = "test";
}

When I do this it shows up in my C# client app as "myFuncA(string* myValue)"
when the intellisense is showing? Is there something else I can do?

Thanks in advance for any suggestions!
 
I found the solution to my problem:

(ie:) Here is the C# version.
void myFuncA(ref string myValue)
{
myValue = "test";
}

(ie:) The solution on how to do this in MC++ is the following.
void myFuncA(System::String^% myValue)
{
myValue = "test";
}

Use the "%" symbol for the equivalent of the "ref" keyword within a C# and
mc++.
 
BartMan said:
I found the solution to my problem:

(ie:) Here is the C# version.
void myFuncA(ref string myValue)
{
myValue = "test";
}

(ie:) The solution on how to do this in MC++ is the following.
void myFuncA(System::String^% myValue)
{
myValue = "test";
}

Use the "%" symbol for the equivalent of the "ref" keyword within a C# and
mc++.

That's actually C++/CLI, which replaced Managed C++. Also % is a tracking
reference, which is like a native reference &, except that it can be updated
by the garbage collector. Your first try would have required that the
String be pinned first.

There's also an OutAttribute which you can tag onto a parameter along with %
to make the equivalent of C# "out" keyword.
 
Back
Top