编辑:什么是 C++/CLI?我在 Visual Studio 中编程,据我所知,使用 C++ ...另外,第一个错误已由 Peter 的评论解决,但我仍然坚持第二个。
我是 C++ 世界的新手,之前我所有的工作都是用 Java 完成的。我不熟悉指针和垃圾收集的使用(尽管我相信我理解这个概念),我相信这可能是我问题的根源。我收到以下错误消息:
1>Runner.cpp(6): error C3145: 'formOutOfTime' : global or static variable may not have managed type 'System::Windows::Forms::Form ^'
1> may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>Runner.cpp(22): error C2061: syntax error : identifier 'FormOutOfTime'
我的代码是这样的:
PurpleHealth.cpp(这是我相信系统调用来启动它的文件):
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
#include "Runner.h"
using namespace PurpleHealth;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
//Application::Run(gcnew FormOutOfTime());
Runner* runner = new Runner();
//delete runner;
return 0;
}
Runner.h(这是我要运行所有主要代码并启动表单的头文件。我也为头文件背后的目的而苦苦挣扎)
#include "stdafx.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
class Runner
{
public:
Runner();
~Runner();
// functions
private:
void Go();
// member variables
};
最后是Runner.cpp:
#include "stdafx.h"
#include "Runner.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"
//Variable Dclaration
System::Windows::Forms::Form^ formOutOfTime;//Error Here***************************
Runner::Runner()
{
// Do stuff if you need to
this->Go();
}
Runner::~Runner()
{
// Clear memory if you need to
}
void Runner::Go()
{
formOutOfTime = gcnew FormOutOfTime();//Error Here***************************
formOutOfTime->ShowDialog();
}
请帮助我解决这些消息,甚至对形式的批评表示赞赏。谢谢。