0

我正在努力找出这种类型的代码:

void changeString (String^% str)
{
    str = "New String";
}

为什么我需要将跟踪引用传递给对象的句柄?这太烦人了。为什么句柄不够,一个句柄类似于c++指针,那为什么不...

谢谢

4

1 回答 1

4

我相信这在精神上与这个 C++ 代码没有什么不同:

void reset_foo(Foo * & p)
{
    p = new Foo;   // leeks, neeps and tatties
}

用法:

Foo * p;
reset_foo(p);

反过来,这只是传递引用的一般概念的一个特例:

void set_int(int & n) { n = 10; }

int a;
set_int(a);
assert(a == 10);
于 2013-07-18T10:52:51.410 回答