2014-10-22 1 views
0

저는 C++을 처음 접했고 제가 만든 게임을위한 클래스 파일을 분리하려고합니다.하지만 그렇게하면 VS에서 많은 오류가 발생합니다.클래스 파일 오류가 발생 했습니까?

Cube.h :

#include "stdafx.h" 
#ifndef CUBE_H 
#define CUBE_H 

struct PlayerCube 
{ 
    //code 

}; 

#endif //CUBE_H 

Cube.cpp :

#include "cube.h" 
#include "stdafx.h" 

using namespace std; 

PlayerCube::PlayerCube(){} 

void PlayerCube::cube_movement(){} 

void PlayerCube::show_cube(){} 

홈페이지 :

#include "cube.h" 
#include "stdafx.h" 

using namespace std; 

int main() 
{ 
    //code 
} 

어떤 아이디어가 도움이 될 것이다! :)

편집 : 키츠 대답은 내 오류를 96에서 3으로 줄였습니다!

는 이제 불과 3 C2679 오류가 없다는이 ">> 진 : 어떤 연산자를 찾을 수 없습니다" , 내 문제를 찾을 수 하나 더 남아

편집!

모든 것이 잘되었지만 프로그램을 실행할 때 충돌이 발생합니다. ".exe가 작동을 멈췄습니다"?

+2

'#include "stdafx.h"* first * include를 항상 만드십시오. [참조] (http://stackoverflow.com/questions/16040689/why-stdfax-h-should-be-the-first-include-on-mfc-applications) – crashmstr

+4

무엇이 오류입니까? – Lochemage

+1

내가보기에 모든 것이 정상적으로 작동해야하지만 전체 코드를 게시하지 않아서 오류가 그 안에 들어있을 수 있습니다. 한가지 작은 오류는'#include "cube.h의 대문자 사용이 메인 파일의 실제 파일 이름 인'Cube.h '와 다르다. 일부 OS는 그것을 좋아하지 않으므로 실제로 파일에 링크하지 않을 것이다. 큐브를 참조하려고하는 모든 것에 오류가 발생합니다. – Lochemage

답변

1

이 비주얼 스튜디오에 특정한 (미리 컴파일 된 헤더) :

  • 이 cube.h에서 STDAFX.H의 포함을 제거는
  • 항상 CPP 파일을에 stdafx.h에 처음 포함

코드는 다음과 같습니다.

,210

Cube.h :

#ifndef CUBE_H 
#define CUBE_H 

struct PlayerCube 
{ 
    //code 

}; 

#endif //CUBE_H 

Cube.cpp :

#include "stdafx.h" 
#include "cube.h" 

using namespace std; 

PlayerCube::PlayerCube(){} 

void PlayerCube::cube_movement(){} 

void PlayerCube::show_cube(){} 

주요 : 당신은 여전히 ​​오류가있는 경우

#include "stdafx.h" 
#include "cube.h" 

using namespace std; 

int main() 
{ 
    //code 
} 

, 귀하의 질문에 포함하십시오.