我的Visual Studio中有一個.NET窗體和一個本機代碼。問題是:我不能在我的本地代碼聲明我的.NET形式的全局實例,就像這樣:在本地代碼中聲明管理變量的C++
Editor^ maineditor;
它給了我這個問題:
error C3145: 'EditorEntry' : global or static variable may not have managed type 'Cube3D::Editor ^'
我的Visual Studio中有一個.NET窗體和一個本機代碼。問題是:我不能在我的本地代碼聲明我的.NET形式的全局實例,就像這樣:在本地代碼中聲明管理變量的C++
Editor^ maineditor;
它給了我這個問題:
error C3145: 'EditorEntry' : global or static variable may not have managed type 'Cube3D::Editor ^'
而不是使用一個全球性的靜態嘗試使得它在一個容器類型
ref class ManagedGlobals {
public:
static Editor^ maineditor = nullptr;
};
THANKs,但是當我定義編輯器時,第二個代碼是這樣來的:具有靜態存儲持續時間的變量不能具有句柄或跟蹤引用類型 – 2012-07-10 18:30:44
而編譯時:'編輯器':全局或靜態變量可能沒有託管類型'Cube3D: :編輯^' – 2012-07-10 18:39:05
@ user1492812 oops,沒有意識到這是一個問題。刪除了答案的部分 – JaredPar 2012-07-10 18:39:13
一個靜態方法包住手柄,gcroot <>結構
gcroot<Editor^> maineditor;
像創造一個虛擬包裝類一樣魅力和乾淨。 – Cameron 2016-04-29 19:07:06
你有你的靜態類往上頂(referece:Can a class be declared static in c++?)
ref class ManagedGlobals abstract sealed {
public:
static Excel::Application^ xl;
};
現在只是引用類
ManagedGlobals::xl = gcnew Excel::Application();
MSDN文章爲C3145文件這個錯誤很好。並且還提供瞭解決方法,使其成爲ref類的靜態成員。 – 2012-07-10 18:23:07