C ++在本机代码中声明托管变量 [英] C++ declaring a managed variable in a native code

查看:116
本文介绍了C ++在本机代码中声明托管变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET表单和Visual Studio中的本机代码.问题是:我无法在本机代码中声明.NET表单的全局实例,如下所示:

I have a .NET form, and a native code in my Visual Studio. The problem is: I can't declare a global instance of my .NET form in my native code, like this:

Editor^ maineditor;

这给了我这个问题:

error C3145: 'EditorEntry' : global or static variable may not have managed type 'Cube3D::Editor ^'

推荐答案

而不是使用全局静态方法,请尝试使其成为容器类型中的静态方法

Instead of using a global static try making it a static method in a container type

ref class ManagedGlobals {
  public:
  static Editor^ maineditor = nullptr;
};

这篇关于C ++在本机代码中声明托管变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆