因此,我是 C++ 编程的新手,但我已将 SDL 与 python 和 FreeBASIC 广泛结合使用。我确定我在这里遗漏了一些愚蠢的东西,但无论我尝试什么,我的 video.h 文件中都会不断收到错误“错误:'命名空间'之前的预期初始化程序”。这让我有点发疯。
#include "SDL/SDL.h"
#include <iostream>
namespace video {
// This is here because like video, everything uses it and the players should never be able to touch it.
int rolldice(int minimumroll, int maximumroll, int numberofdice);
// Same Here.
char* charraystring(std::string prestring);
// Now we're in video proper
// This function loads an image, checks to make sure it works, returns the image, and unloads the testing surface.
SDL_Surface* loadimage(std::string path);
// This is an optimized blitter that will exit with a signal if it encounters an error.
void oblit(SDL_Surface* pic, SDL_Rect frame, SDL_Surface* screen, SDL_Rect location);
}
最佳答案
您提供的错误 error: expected initializer before ‘namespace’
表明存在未终止的结构或变量声明。像这样的东西:
struct foo {
...
}
namespace video {
...
在这里,'struct foo' 声明没有以分号结束。这应该是:
struct foo {
...
};
namespace video {
...
让预处理器参与进来(使用#include)使得这类事情更难追踪。例如,您可能包含了一个不终止结构定义的 header (就在 namespace video
声明之前)。
去检查你所有的 struct
s 和 class
es 在你的头文件和源文件中的右大括号之后有一个分号。同样,任何变量声明,例如
int value // <-- oops, forgot the ';'
namespace video {
...
关于c++ - 命名空间之前的预期初始化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9103454/