reference undefinded

Discussion in 'C++' started by Michael Sgier, Aug 16, 2006.

  1. Hi
    why that error?
    Main.cpp:(.text+0xd0f): undefined reference to
    `CJoysticksManager::CJoysticksManager()'

    the constructor is in Joysticks.h:
    class CJoysticksManager : public CStreamObject
    {
    public:
    CJoysticksManager();



    in main.cpp:
    globals->joymgr = new CJoysticksManager();

    and in globals.h:
    CJoysticksManager *joymgr;

    headers are included:
    #include "../Include/FlyLegacy.h"
    #include "../Include/Joysticks.h"
    #include "../Include/Globals.h"



    --
    Linuxgames: http://shop.sgier.com
    Michael Sgier, Aug 16, 2006
    #1
    1. Advertising

  2. Michael Sgier schrieb:
    > Hi
    > why that error?
    > Main.cpp:(.text+0xd0f): undefined reference to
    > `CJoysticksManager::CJoysticksManager()'
    >
    > the constructor is in Joysticks.h:
    > class CJoysticksManager : public CStreamObject
    > {
    > public:
    > CJoysticksManager();


    You have to _define_ the constructor. You need a function body somewhere.

    --
    Thomas
    Thomas J. Gritzan, Aug 16, 2006
    #2
    1. Advertising

  3. Well that's in main too. Did you mean that?

    // General-purpose global settings
    SGlobals *globals = NULL;

    How should I define CJoysticksManager otherwise?
    Any example? Thanks and regards
    Michael
    PS: I don't really understand this whole structure
    Why like this: globals->joymgr
    It looks very complicated to me...but Im still a
    C++ newbie.
    Michael Sgier, Aug 17, 2006
    #3
  4. Michael Sgier

    Jim Langston Guest

    "Michael Sgier" <> wrote in message
    news:23c08$44e2ea6e$c299b72a$...
    > Hi
    > why that error?
    > Main.cpp:(.text+0xd0f): undefined reference to
    > `CJoysticksManager::CJoysticksManager()'
    >
    > the constructor is in Joysticks.h:
    > class CJoysticksManager : public CStreamObject
    > {
    > public:
    > CJoysticksManager();
    >
    >
    >
    > in main.cpp:
    > globals->joymgr = new CJoysticksManager();
    >
    > and in globals.h:
    > CJoysticksManager *joymgr;
    >
    > headers are included:
    > #include "../Include/FlyLegacy.h"
    > #include "../Include/Joysticks.h"
    > #include "../Include/Globals.h"


    As Thomas said, you need to define the constructor somewhere since you
    declared it.

    If it doesn't have to do anythign special a simple empty function body would
    work.

    CJoystickManager::CJoystickManager
    {
    }

    Personally, if I have an empty body I usually put them with the declaration
    anyway, so if it was me I would change it to:

    class CJoysticksManager : public CStreamObject
    {
    public:
    CJoysticksManager() {};

    Others may have other opionions.
    Jim Langston, Aug 18, 2006
    #4
  5. Michael Sgier

    Old Wolf Guest

    Jim Langston wrote:
    >
    > If it doesn't have to do anythign special a simple empty function body would
    > work.
    >
    > CJoystickManager::CJoystickManager
    > {
    > }


    Should be:

    CJoystickManager::CJoystickManager()
    {
    }
    Old Wolf, Aug 18, 2006
    #5
    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. Darren
    Replies:
    0
    Views:
    494
    Darren
    Oct 11, 2004
  2. Dude
    Replies:
    0
    Views:
    353
  3. ce
    Replies:
    1
    Views:
    2,987
  4. sam pal
    Replies:
    3
    Views:
    540
    E. Robert Tisdale
    Jul 16, 2003
  5. Mount Everist

    C/C++ undefinded symbol problem

    Mount Everist, Nov 25, 2004, in forum: C++
    Replies:
    3
    Views:
    373
    Jonathan Mcdougall
    Nov 27, 2004
Loading...

Share This Page