By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,917 Members | 1,313 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,917 IT Pros & Developers. It's quick & easy.

static error

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a


Allan Bruce wrote:

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?

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #2

P: n/a

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:3F***************@gascad.at...


Allan Bruce wrote:

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?


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
Jul 19 '05 #3

P: n/a
"Allan Bruce" <al*****@TAKEAWAYf2s.com> writes:
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

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.