2012-07-10 102 views
1

我目前有一個main.cpp和一個editor.hC++從本機代碼的另一種形式獲取價值?

這個editor.h是託管代碼 main.cpp是本地代碼。

在main.cpp中我通常會運行編輯器的一個新實例:

Application::Run(gcnew Editor()); 

但隨後在main.cpp中另一個地方,我想提取這種形式的值,所以我懷疑是我乾的像這樣: (main.cpp中)

.... 
Editor^ EditorEntry; 
.. 
.. 
EditorEntry::Value1.... 
EditorEntry::Panel1->Name... 

int main(..) 
{ 
... 
Application::Run(gcnew EditorEntry()); 
... 
} 

,但我不能,而得到這樣的:

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

那麼我該怎麼做呢?

+1

Move Editor^EditorEntry;成主要(..)。您可以使用Visual Studio嚮導生成的全新Windows Fowms應用程序進行檢查。但無論如何,你爲什麼認爲你需要編輯器的全局實例? – Simon 2012-07-10 09:06:17

+0

因爲我想從main之外收集一個值,在main.cpp – 2012-07-10 09:33:22

+0

任何人都可以幫我嗎? – 2012-07-10 13:16:34

回答

0

需要讀取編輯器值的代碼片段是否需要本機代碼?它可能在另一個託管類中嗎?例如,您可以將編輯器傳遞給此類,以便它可以讀取其屬性。

int main(..) 
{ 
    EditorEntry^ editor = gcnew EditorEntry(); 
    EditorObserver^ observer = gcnew EditorObserver(editor); 

    Application::Run(editor); 
    ... 
} 

EditorObserver將保持場與EditorEntry在其構造過去了,就能夠訪問它的公共接口,偵聽其事件等

在面向對象的應用程序,你不會無論如何,在main.cpp中放置了太多的代碼。

相關問題