tags:

views:

147

answers:

2

I have some extern'd variables in a namespace in a header file, and I'm trying to initialize them in its corresponding cpp file. However, I keep getting the error given in the topic title. I'm not sure what the problem is.

EX:

// Some header
namespace foo
{
    extern SDL_Surface* bar;
}

// In the impl file
#include "someheader.h"
foo::bar = 0;
.....

Any assistance is appreciated. Thanks.

+4  A: 

At the file level, you can only define types (you've only written an assignment expression). So you need to change that to:

SDL_Surface* foo::bar = 0;
R Samuel Klatchko
Perfect. Thank you.
Anonymous
Or he would have to move that statement within any of the functions.
Technowise
@Technowise - the problem is he will then be lacking a definition of the variable and the linker will fail with a missing symbol.
R Samuel Klatchko
A: 

It doesn't know what type SDL_Surface is. You need to define it or at least forward declare it.

jmucchiello
The example was just an example, not the actual code. I can assure you it knows what an SDL_Surface is. I'll edit the example to be more clear.
Anonymous