"指针" in / clr [英] "pointers" in /clr
问题描述
在过去的日子中,我们可以创建一个指向变量实例的指针
,如下所示:
int i = 58 ;
int * i_ptr =& i;
int j = * i_ptr; // j = 58
现在,在/ clr我们如何做同样的事情?也就是说,如果我用'''''替换''*''
,我将''&''替换成'''指针''(是''x ^ ''对某个实例称为''参考''
每次机会
?)那就是:
ref class myClass(){...};
myClass i;
myClass ^ i_ptr =& i; //错误,使用什么而不是''&''?
myClass j = * i_ptr; //错误(我想),做什么呢?
[== P ==]
In the ''old days'', we could create a pointer to an instance of a variable
like so:
int i = 58 ;
int* i_ptr = &i ;
int j = *i_ptr ; // j = 58
Now, in /clr how do we do the same? That is, if I replace ''*'' with ''^'' what
do I replace ''&'' with to generate a ''pointer'' (is ''x^'' called a ''reference''
per chance?) to the instance? That is:
ref class myClass() {...} ;
myClass i ;
myClass^ i_ptr = &i ; // error, use what instead of ''&''?
myClass j = *i_ptr ; // error (i think), do what instead?
[==P==]
推荐答案
ref class R
{
。 。 。
};
.. 。
R r1;
R ^ r2 =%r1;
R%r3 = * r2;
-
问候,
Nish [VC ++ MVP]
" Peter Oliphant" < PO ******* @ RoundTripInc.com>在留言中写道
新闻:%2 **************** @ TK2MSFTNGP15.phx.gbl ...
ref class R
{
. . .
};
.. . .
R r1;
R^ r2 = %r1;
R% r3 = *r2;
--
Regards,
Nish [VC++ MVP]
"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
在''old days'',我们可以像这样创建一个指向变量实例的指针:
int i = 58;
int * i_ptr =& i;
int j = * i_ptr; // j = 58
现在,在/ clr我们如何做同样的事情?也就是说,如果我将''*''替换为''^''
我用什么来代替''&''来生成''指针''(是''x ^''称为''
'参考''每次机会?)到实例?那就是:
ref class myClass(){...};
myClass i;
myClass ^ i_ptr =& i; //错误,使用什么而不是''&''?
myClass j = * i_ptr; //错误(我想),做什么呢?
[== P ==]
In the ''old days'', we could create a pointer to an instance of a variable
like so:
int i = 58 ;
int* i_ptr = &i ;
int j = *i_ptr ; // j = 58
Now, in /clr how do we do the same? That is, if I replace ''*'' with ''^''
what do I replace ''&'' with to generate a ''pointer'' (is ''x^'' called a
''reference'' per chance?) to the instance? That is:
ref class myClass() {...} ;
myClass i ;
myClass^ i_ptr = &i ; // error, use what instead of ''&''?
myClass j = *i_ptr ; // error (i think), do what instead?
[==P==]
Peter Oliphant < PO ******* @ RoundTripInc.com>写了
"Peter Oliphant" <po*******@RoundTripInc.com> wrote
ref class myClass(){...};
myClass i;
myClass ^ i_ptr =& i; //错误,使用什么而不是''&''?
myClass ^ i_ptr =%i;
myClass j = * i_ptr; //错误(我认为),做什么呢?
ref class myClass() {...} ;
myClass i ;
myClass^ i_ptr = &i ; // error, use what instead of ''&''? myClass^ i_ptr = %i;
myClass j = *i_ptr ; // error (i think), do what instead?
这很好,只要定义了复制文件。 C ++ / CLI
确实_not_自动为ref类定义复制ctors
* sigh *。
如果你想要
相当于你可以写的C ++引用(int%)
myClass%j = * i_ptr;
-hg
That''s fine, so long as a copy ctor is defined. C++/CLI
does _not_ automatically define copy ctors for ref classes
* sigh *.
If you want
the equivalent to a C++ reference (int%) you can write
myClass% j = *i_ptr;
-hg
你好Holger,
其实我问的原因是因为我需要创建一份副本
构造函数,我不能不知道这些语法''等价''
''指针''和''''的内容......:)
也就是说,我不知道这是ref
类的复制构造函数的形式:
ref class refClass
{
refClass(refClass%other){}
};
[== P ==]
" Holger Grund" < hg@remove.ix-n.net>在消息中写道
news:eN ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Holger,
In fact, the reason I asked was because I needed to create a copy
constructor and I couldn''t without knowing these syntax ''equivalences'' to
''pointer'' and ''contents of''... : )
That is, I didn''t know this is the form of a copy constructor for a ref
class:
ref class refClass
{
refClass( refClass% other ) {}
} ;
[==P==]
"Holger Grund" <hg@remove.ix-n.net> wrote in message
news:eN**************@TK2MSFTNGP09.phx.gbl...
" Peter Oliphant" < PO ******* @ RoundTripInc.com>写了
"Peter Oliphant" <po*******@RoundTripInc.com> wrote
ref class myClass(){...};
myClass i;
myClass ^ i_ptr =& i; //错误,使用什么而不是''&''?
ref class myClass() {...} ;
myClass i ;
myClass^ i_ptr = &i ; // error, use what instead of ''&''?
myClass ^ i_ptr =%i;
myClass^ i_ptr = %i;
myClass j = * i_ptr; //错误(我认为),做什么呢?
myClass j = *i_ptr ; // error (i think), do what instead?
只要定义了复制文件,那就没问题了。 C ++ / CLI
确实_not_自动为ref类定义copy ctors
*叹*。
如果你想要相当于C ++引用(int%)你可以写
myClass%j = * i_ptr;
-hg
That''s fine, so long as a copy ctor is defined. C++/CLI
does _not_ automatically define copy ctors for ref classes
* sigh *.
If you want
the equivalent to a C++ reference (int%) you can write
myClass% j = *i_ptr;
-hg
这篇关于"指针" in / clr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!