.net - C++/CLI 引用变量

标签 .net c++-cli

void f(cli::array<PointF> ^points){
    PointF& a = points[0];
    // and so on...
}

第 2 行出现编译错误。

.\ndPanel.cpp(52) : error C2440: 'initializing' : cannot convert from 'System::Drawing::PointF' to 'System::Drawing::PointF &'
        An object from the gc heap (element of a managed array) cannot be converted to a native reference

声明引用变量的托管方式是什么?

最佳答案

如果您只想声明对数组中第一个 PointF 的引用,那么您需要使用 tracking reference (%):

void f(cli::array<PointF>^ points)
{    
    PointF% a = points[0];
}

关于.net - C++/CLI 引用变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/245957/

相关文章:

.net - 如何优雅地关闭另一个应用程序?

visual-studio-2010 - 你如何将 'System::String ^' 转换为 'TCHAR' ?

.net 2.0安全配置

c# - 如何以编程方式连接到需要 SSH 隧道的远程数据库服务器?

c# - 根据可变数量的空格拆分字符串

c# - 使用 SSH.NET 连接到 OpenSSH 7.4p1 失败并显示 "The server response contains a null character at position"但在 WinSCP 中有效

c# - 如何将此 C# 代码转换为 C++/CLI

c++ - 内存泄漏、大量位图图像 C++ CLI

c# - 使用不安全将指向 CLR 类型的指针分配给 void*?

.net - Autofac + SignalR