static error

A

Allan Bruce

Hi there,
I get a linker error with the following, can somebody tell me how to remedy
it? the error is:
--------------------Configuration: WinGalaga - Win32
Release--------------------
Linking...
Weapon.obj : error LNK2001: unresolved external symbol "protected: static
int Weapon::mCurrLight" (?mCurrLight@Weapon@@1HA)
WeaponManager.obj : error LNK2001: unresolved external symbol "protected:
static int Weapon::mCurrLight" (?mCurrLight@Weapon@@1HA)
Release/WinGalaga.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

WinGalaga.exe - 3 error(s), 0 warning(s)


I am trying to initialise the lights from the WeaponManager by:
Weapon::InitLights();


Here is the header of the file where the problem exists


class Weapon : public GameEntity
{
friend class WeaponManager;

public:
Weapon(void);
virtual ~Weapon(void);

virtual void Draw(void);
void DrawLight(void);
static void InitLights(void){mCurrLight = GL_LIGHT1;}

...

protected:
...
// light stuff
static int mCurrLight;
};


Thanks
Allan
 
K

Karl Heinz Buchegger

Allan said:
Here is the header of the file where the problem exists

class Weapon : public GameEntity
{
friend class WeaponManager;

public:
Weapon(void);
virtual ~Weapon(void);

virtual void Draw(void);
void DrawLight(void);
static void InitLights(void){mCurrLight = GL_LIGHT1;}

...

protected:
...
// light stuff
static int mCurrLight;
};

this *declares* a variable mCurrLight. But it does not *define* it.
In other words: the above says: Somewhere there is a variable
called Weapon::mCurrLight and it has type int.
But where is that variable?
You have to define it somewhere, eg. in Weapon.cpp

#include "Weapon.h"

int Weapon::mCurrLight; // Here it is!!!

Weapon::Weapon()
{
...


Your textbook should have a section on statis class members. Doesn't it?
 
A

Allan Bruce

Karl Heinz Buchegger said:
this *declares* a variable mCurrLight. But it does not *define* it.
In other words: the above says: Somewhere there is a variable
called Weapon::mCurrLight and it has type int.
But where is that variable?
You have to define it somewhere, eg. in Weapon.cpp

#include "Weapon.h"

int Weapon::mCurrLight; // Here it is!!!

Weapon::Weapon()
{
...


Your textbook should have a section on statis class members. Doesn't it?

Thanks, thats it working now.

My book does have a section on static members, but it is not explained very
well. I understand why you need the inclusion of Weapon::mCurrLight;

Thanks again
Allan
 
F

Frank Schmitt

Allan Bruce said:
Hi there,
I get a linker error with the following, can somebody tell me how to remedy
it? the error is:
--------------------Configuration: WinGalaga - Win32
Release--------------------
Linking...
Weapon.obj : error LNK2001: unresolved external symbol "protected: static
int Weapon::mCurrLight" (?mCurrLight@Weapon@@1HA)
WeaponManager.obj : error LNK2001: unresolved external symbol "protected:
static int Weapon::mCurrLight" (?mCurrLight@Weapon@@1HA)
Release/WinGalaga.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

WinGalaga.exe - 3 error(s), 0 warning(s)


I am trying to initialise the lights from the WeaponManager by:
Weapon::InitLights();


Here is the header of the file where the problem exists


class Weapon : public GameEntity
{
friend class WeaponManager;

public:
Weapon(void);
virtual ~Weapon(void);

virtual void Draw(void);
void DrawLight(void);
static void InitLights(void){mCurrLight = GL_LIGHT1;}

...

protected:
...
// light stuff
static int mCurrLight;
};

You have *declared* Weapon::mCurrLight, but you haven't *defined* it -
just add

int Weapon::mCurrLight;

to Weapon.cpp

HTH & kind regards
frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top