Error "C3145" and "C2061" in C++ Visual Studio

EDIT: What is C++/CLI? I am programming in Visual studio, and as far as I know using C++... Also, The first error was solved by Peter's comment, but I am still stuck on the second.

I am brand new to the world of C++, and have previously done all my work in Java. I am unfamiliar with the use of pointers and garbage collection (though I believe I understand the concept) and I believe that may be the source of my problems. I am getting the following error messages:

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'

My code is like this:

PurpleHealth.cpp (This is the file I believe the system calls to start it all off):

#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 (this is the header file I want to run all my main code, and launch the forms. I also struggle with the purpose behind the header files)

#include "stdafx.h"
#include "FormOutOfTime.h"
#include "FormParentalOverride.h"

class Runner
{
public:

    Runner();
    ~Runner();

    // functions

private:

    void Go();
    // member variables

};

And Finally 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();
}

Please help me solve these messages, and even critique on form is appreciated. Thanks.

Answers


managed pointers cannot be declared at static or global scope. They can only be declared at function scope. Move the declaration of formOutOfTime from the top of the runner.cpp file to within the Go method


Need Your Help

Windows active directory- Directory size quotas?

windows active-directory quota

A system I have come across, that uses active directory, and has disk quotas, does not have the quotas tranparent to the user. All the users displays in windows (my computer etc.) and calls to

how do I call the name of the file

php mysql

I am new to php so please forgive me. I am trying to do an image upload to the server and then upload the image name to the database so that I can call it out. However, when I try to insert the image