2012-07-10 99 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中放置了太多的代码。

相关问题