我开始使用SDL库在C++中为我的学校项目开发游戏。但我无法找到我在下面的代码中做错了什么。SDL/C++包含问题
我使用VC++ 2008,
这里是compilator输出:
1>Compiling...
1>initGame.cpp
1>.\dec.h(4) : error C2065: 'SDL_HWSURFACE' : undeclared identifier
1>.\dec.h(4) : error C2065: 'SDL_DOUBLEBUF' : undeclared identifier
1>.\dec.h(6) : error C2143: syntax error : missing ';' before '*'
1>.\dec.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\dec.h(6) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\dec.h(6) : error C2065: 'NULL' : undeclared identifier
1>.\initgame.cpp(4) : error C2065: 'SDL_INIT_VIDEO' : undeclared identifier
1>.\initgame.cpp(4) : error C2065: 'SDL_INIT_AUDIO' : undeclared identifier
1>.\initgame.cpp(4) : error C2065: 'SDL_INIT_TIMER' : undeclared identifier
1>.\initgame.cpp(4) : error C3861: 'SDL_Init': identifier not found
1>.\initgame.cpp(5) : error C2065: 'cerr' : undeclared identifier
1>.\initgame.cpp(5) : error C2065: 'endl' : undeclared identifier
1>.\initgame.cpp(9) : error C3861: 'SDL_SetVideoMode': identifier not found
这里是源
dec.h:
#ifndef DEC_H
#define DEC_H
int g_win_flags = SDL_HWSURFACE|SDL_DOUBLEBUF;
SDL_Surface *g_screen = NULL;
#endif
initGame.cpp :
#include "dec.h"
bool initGame(){
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) == -1){
cerr << "Unable to initialize SDL" << endl;
return false;
}
g_screen = SDL_SetVideoMode(640, 480, 0, g_win_flags);
return true;
}
main.cpp中:
#include <iostream>
#include <SDL.h>
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
using namespace std;
#include "initGame.cpp"
int main(int argc, char *argv[]){
initGame();
return 0;
}
我将不胜感激,如果有人能帮助我。
在此先感谢有一个愉快的一天:)
@Zod - 解开你重新标记。这是一个C++问题。这个问题不是特定于visual C++的。 – 2010-11-01 19:44:25
哦,男人,在这段代码中有这么多小事情向我提出警告。有些人可能会称它为代码风格。 – 2010-11-01 20:37:52