名称空间前的预期初始化程序

时间:2012-02-01 21:13:53

标签: c++ sdl initializer

所以,我对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);
}

1 个答案:

答案 0 :(得分:11)

您提供的错误error: expected initializer before ‘namespace’表明存在未终止的结构或变量声明。类似的东西:

struct foo {
    ...
}

namespace video {
    ...

这里,'struct foo'声明不以分号结尾。这应该是:

struct foo {
    ...
};

namespace video {
    ...

使用预处理器(使用#include)会使这类事情更难以追踪。例如,可能是您包含一个标题(就在发出namespace video声明之前)并不终止结构定义。

在标题和源文件中关闭大括号后,检查所有structclass es是否都有分号。类似地,任何变量声明,例如

int value // <-- oops, forgot the ';'

namespace video {
    ...