ref and out in C++/CLI

孤人 提交于 2019-12-03 09:06:52

问题


I know that the C++/CLI code

void foo(Bar^% x);

transforms into

Void foo(ref Bar x);

What is the C++/CLI code that becomes

Void foo(out Bar x);

?


回答1:


You can use the OutAttribute:

using namespace System::Runtime::InteropServices;    
void foo([Out] Bar^% x); 



回答2:


There is no such specific syntax in C++/CLI. I think you can get fairly close by adding the OutAttribute to modify the parameter. But I'm not sure that achieves the exact same semantics as C# out.

The concept of out is for the most part limited to C#. The CLR really only sees ref parameters. The out concepts is achieved via a mod opt I believe and most languages ignore it.



来源:https://stackoverflow.com/questions/3514237/ref-and-out-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!