static error

Discussion in 'C++' started by Allan Bruce, Nov 7, 2003.

  1. Allan Bruce

    Allan Bruce Guest

    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
    Allan Bruce, Nov 7, 2003
    #1
    1. Advertising

  2. 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
    Karl Heinz Buchegger, Nov 7, 2003
    #2
    1. Advertising

  3. Allan Bruce

    Allan Bruce Guest

    "Karl Heinz Buchegger" <> wrote in message
    news:...
    >
    >
    > 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
    Allan Bruce, Nov 7, 2003
    #3
  4. "Allan Bruce" <> 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
    Frank Schmitt, Nov 7, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Natan

    Static vs. non-static connection

    Natan, May 24, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    7,299
    Sami Vaaraniemi
    May 26, 2004
  2. Ben
    Replies:
    3
    Views:
    404
  3. Paul W

    Static is REALLY Static!

    Paul W, May 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    363
  4. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    Why do static and non-static method names collide?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 2, 2003, in forum: Java
    Replies:
    12
    Views:
    5,584
    cgbusch
    Jul 5, 2003
  5. utab
    Replies:
    5
    Views:
    573
    Thomas Tutone
    May 16, 2006
Loading...

Share This Page