mc++ and pass by reference

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!
 
G

Guest

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++.
 
B

Ben Voigt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top