Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected initializer before namespace

So, I'm fairly new to C++ programming but I have used SDL extensively with python and FreeBASIC. I'm sure I'm missing something silly here, but no matter what I try I keep getting the error "error: expected initializer before ‘namespace’" in my video.h file. It's driving me a little crazy.

#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);
}
like image 603
Jsmith Avatar asked Dec 12 '22 05:12

Jsmith


1 Answers

The error you offer, error: expected initializer before ‘namespace’ suggests that there is a structure or variable declaration that isn't terminated. Something like:

struct foo {
    ...
}

namespace video {
    ...

Here, the 'struct foo' declaration isn't terminated with a semicolon. This should read:

struct foo {
    ...
};

namespace video {
    ...

Getting the preprocessor involved (using #include) makes this type of thing a bit harder to track down. It may be that you include a header (just before making the namespace video declaration) that doesn't terminate a structure definition, for example.

Go and check that all of your structs and classes have a semicolon after the closing curly brace in your headers and source files. Similarly any variable declarations, e.g.

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

namespace video {
    ...
like image 147
Managu Avatar answered Dec 30 '22 02:12

Managu