ref类和引用值 [英] ref Class and a value by reference
问题描述
我要做的是从ref
类中的函数中获取值。
在这种情况下,我不能使用参考和外出运营商。
我已经尝试了所有我能想象的但仍然无法正常工作。
使用阵列效果很好。
void更改(int a,array< int> ^ m)
{
m [0] = a;
}
使用此代码,在调用Change的函数中,值将改为
。
但是使用int它不起作用
void更改(int a,int ^ m)
{
m = a;
}
有什么猜测吗?
Hi, what i''m trying to do is obtaining a value from a function in a ref
class.
In this context I can''t use the "ref" and "out" operators.
I have tried all i can imagine but still hasn''t it working.
With an array it works great.
void Change(int a, array<int>^ m)
{
m[0]=a;
}
With this code, in the function that calls Change the value will be
changed.
But with an int it doesnt work
void Change(int a, int^ m)
{
m=a;
}
Any guess?
推荐答案
> void Change(int a,int ^ m)
{
m = a;
}
任何猜测?
>void Change(int a, int^ m)
{
m=a;
}
Any guess?
我的猜测是你发布到了错误的新闻组。这个是用于
C#,而不是C ++。但C ++ / CLI参考参数语法是,IIRC
void更改(int a,int ^%m)
Mattias
>
-
Mattias Sj?gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请回复到新闻组。
My guess is that you posted to the wrong newsgroup. This one is for
C#, not C++. But the C++/CLI reference parameter syntax is, IIRC
void Change(int a, int^% m)
Mattias
--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
" Mattias Sj?gren" < ma ******************** @ mvps.orgwrote in message
news:Og ********** **** @ TK2MSFTNGP03.phx.gbl ...
"Mattias Sj?gren" <ma********************@mvps.orgwrote in message
news:Og**************@TK2MSFTNGP03.phx.gbl...
我的猜测是你发布到了错误的新闻组。这个是用于
C#,而不是C ++。但是C ++ / CLI参考参数语法是,IIRC
void更改(int a,int ^%m)
My guess is that you posted to the wrong newsgroup. This one is for
C#, not C++. But the C++/CLI reference parameter syntax is, IIRC
void Change(int a, int^% m)
实际上C ++中的语法将是
void更改(int a,int& m){}
- Alan
Actually the syntax in C++ would be
void Change(int a, int& m) {}
-- Alan
在C ++ / CLI中:
^%用于通过引用传递引用类型。
%用于通过引用传递值类型。
例如,
路过ref:
void test(int%myInt,System :: Object ^%myObject)
vs传递值:
void test(int myInt,System :: Object ^ myObject)
-
David Anton
www.tangiblesoftwaresolutions.com
即时C#:VB到C#转换器
即时VB:C#到VB转换器
即时C ++:C#/ VB到C ++转换器
C#代码指标:C#的快速指标
" Mattias Sj ?? gren"写道:
In C++/CLI:
^% is for passing reference types by ref.
% is for passing value types by ref.
e.g.,
passing by ref:
void test(int %myInt, System::Object ^%myObject)
vs passing by value:
void test(int myInt, System::Object ^myObject)
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
C# Code Metrics: Quick metrics for C#
"Mattias Sj??gren" wrote:
>
>
void更改(int a,int ^ m)
{
m = a;
}
有什么猜测?
void Change(int a, int^ m)
{
m=a;
}
Any guess?
我的猜测是你发布到了错误的新闻组。这个是用于
C#,而不是C ++。但C ++ / CLI参考参数语法是,IIRC
void更改(int a,int ^%m)
Mattias
-
Mattias Sj ?? gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
请回复到新闻组。
My guess is that you posted to the wrong newsgroup. This one is for
C#, not C++. But the C++/CLI reference parameter syntax is, IIRC
void Change(int a, int^% m)
Mattias
--
Mattias Sj??gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
这篇关于ref类和引用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!