2012-07-17 2 views
1

편집 : C++/CLI 란 무엇입니까? 나는 Visual Studio에서 프로그래밍을하고 있으며, C++을 사용하여 아는 한 ... 또한 첫 번째 오류는 Peter의 의견에 의해 해결되었지만 여전히 두 번째 오류에 집착하고 있습니다.C++ Visual Studio에서 "C3145"및 "C2061"오류

나는 C++ 세계에 새로운 브랜드이며, 이전에 자바로 모든 작업을 해왔다. 나는 포인터와 가비지 콜렉션의 사용에 익숙하지 않다. (비록 내가 개념을 이해한다고 믿지만) 나는 그것이 내 문제의 근원일지도 모른다. 나는 다음과 같은 오류 메시지가 점점 오전 :

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 

}; 
,691

그리고 마지막으로 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(); 
} 

나에게 이러한 메시지를 해결하는 데 도움이, 심지어 감사 양식에 비판하시기 바랍니다. 감사.

+1

C++에는 가비지 수집이 없으며 포인터를 나타내는 '^'은 C++가 아닙니다. – chris

+0

이것은 [C++/CLI] (http://en.wikipedia.org/wiki/C%2B%2B/CLI)입니까? –

+1

예, 이것은 C++가 아닙니다. –

답변

2

관리되는 포인터는 정적 또는 전역 범위에서 선언 할 수 없습니다. 함수 범위에서만 선언 할 수 있습니다. runner.cpp 파일의 맨 위에서 formOutOfTime 선언을 Go 메서드 내로 옮깁니다.

관련 문제