473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

static error

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
3 5136


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

"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: IHateSuperman | last post by:
public class StaticField2{ public static void main(String args){ private int x, y; // <<== error 1 for ( y = 0 ; y < 100 ; y++){ x = StaticMethod(); System.out.println(" x = "+x); } } public...
1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
29
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
1
by: Bryan Parkoff | last post by:
I know how to write "Pointer to Function" inside struct or class without using static, but I have decided to add static to all functions inside struct or class because I want member functions to be...
2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
13
by: jamihuq | last post by:
Can someone please tell me what I am doing wrong. I wrote this static inline function to test another function and I am getting errors which make no sense to me. thanks Jami /* test2.h */ ...
1
by: wenqiang.zhou | last post by:
i only kown that static members doesnt blong to any object and it have to initialize outside class, inline is near the same as define it will replace in code.but i was puzze by the following codes....
5
by: mast2as | last post by:
Hi guys Here's the class I try to compile (see below). By itself when I have a test.cc file for example that creates an object which is an instance of the class SpectralProfile, it compiles...
4
by: Jon Skeet [C# MVP] | last post by:
On Aug 11, 5:11 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> wrote: Exactly. My favourite example is Thread.Sleep. Suppose this code were valid (its equivalent in Java is, for example): ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.