Expected initializer before namespace

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 {
    ...

Leave a Comment

tech