c ++ / cx通过引用传递值struct

时间:2015-08-20 13:05:16

标签: visual-studio-2015 c++-cx

"如果您将值类型作为函数或方法参数,则通常按值传递。对于较大的对象,这可能会导致性能问题。在Visual Studio2013和更早版本中,C ++ / CX中的值类型始终按值传递。在Visual Studio 2015及更高版本中,您可以通过引用或值传递值类型。"

这对我来说不起作用,使用value_struct&在函数签名中,编译器发出:

  

错误 C3987'设置':公共成员的签名包含本机类型value_struct& ...没有参考的工作,Visual Studio 2015

我错过了什么?

1 个答案:

答案 0 :(得分:0)

I was able to get this to work like this:

public interface class MyDelegate {
    void MyDelegateMethod(Platform::String^ str,
        Windows::Foundation::Point *point);
}

.. and in the C# delegate implementation:

public void MyDelegateMethod(string str, out Point p) { ... }

It's mentioned in the MS page on this stuff (https://msdn.microsoft.com/en-us/library/hh699861.aspx):

You can also use a pointer symbol (*) to pass a value type by reference. The behavior with respect to callers in other languages is the same (callers in C# use the ref keyword), but in the method, the type is a pointer to the value type.