I’ve created a structure in a header file as follows:
typedef struct
{
GLfloat lgtR, lgtG, lgtB, lgtA;
GLfloat x, y, z;
bool islight;
GLfloat width, height, depth;
GLenum lightn;
particle prt;
int maxprt;
} emitter;
which works without a problem.
However, in that particular header file, I want to declare a global emitter that I can use in all the functions and isn’t part of the main source file:
// header.h global declaration
emmiter currentEmit;
GLvoid glSetEmitter(emitter emitter)
{
currentEmit = emitter;
}
However, when I do try this, I get a whole lot of “error C2228: left of ‘.variable’ must have class/struct/union, so I’m assuming it’s not declaring my structure here at all.
Is there a way to declare that structure globally within a header file, and if so, is there also a way to keep it from being part of the other .cpp files as well?
emitteris not the same asemmiter.Also, since this is C++ – just write
struct {};directly, there’s no need for atypedef.Your whole header is wrong, and will give multiple definitions if included in multiple translation units:
currentEmitneeds to be defined in a single implementation file, not a header. The function needs to beinlineso it’s not defined by all TU.Last thing: pass the parameter by const reference:
Otherwise an unnecessary copy will be created.