2016-12-16 2 views
1

여기서 잘못된 것은 무엇입니까?헤더 파일에 선언 된 네임 스페이스가 소스 파일에서 인식되지 않습니다.

APP_H,

#pragma once 

namespace App{ 

    enum class AppStatus{ 
    Exit, 
    Menu, 
    Run 
    }; 

    void frameLoop(); 

    AppStatus state; 

} 

App.cpp

#include "App.h" 
#include "stdafx.h" 
#include <Graphic\Graphic.h> 


void App::frameLoop() 
{ 
    while (state != AppStatus::Exit) { 

     Graphic::renderingSequence(); 
    } 
} 

오류

Error C2653 'App': is not a class or namespace name App 
Error C2065 'state': undeclared identifier App 
Error C2653 'AppStatus': is not a class or namespace name App 
Error C2065 'Exit': undeclared identifier App  

주 내 네임 스페이스그(\ Graphic \ Graphic.h에 선언되어 있음)은 컴파일러가 인식하고 있습니다.

+1

'사용법 #include "stdafx.h를은"'항상 첫 번째 비 주석 행이어야합니다. 그 위의 모든 행은 컴파일러에서 무시됩니다. – drescherjm

+0

이것은 중복되어야합니다. – drescherjm

+0

감사! '#include ' – stimulate

답변

2

stdafx.h (Microsoft 사전 컴파일 된 머리글)는 맨 위에 있어야합니다. 이 미리 컴파일 된 헤더 옵션을 설정하고 stdafx.h 표준 pch 모든 Visual C++ 프로젝트에 적용됩니다. 그것들은 새 프로젝트의 기본 설정입니다.

Purpose of stdafx.h

네임 스페이스 응용 프로그램 내에서 함수를 정의하는 가장 간단하고 최소 오류가 발생하기 쉬운 방법은 이 넣어 단지이다.

APP.CPP

#include "stdafx.h" // Nothing goes above this 
#include "App.h" 
#include <Graphic\Graphic.h> 

namespace App { 
    void frameLoop() 
    { 
     while (state != AppStatus::Exit) { 
      Graphic::renderingSequence(); 
     } 
    } 
} 
+0

Jive에 동의하면 App :: frameLoop()을 말하는 것이 아니라 네임 스페이스에 함수를 넣어야합니다. 사람들에게 혼란을 줄 수 있으며, App이 수업이라고 생각할 수도 있습니다. –

+0

더 중요한 것은 cpp 파일의 코드가 .h 파일과 동일한 이름을 자동으로 해석한다는 것입니다. 예 : AppStatus :: 종료. –