reference undefinded

M

Michael Sgier

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"
 
T

Thomas J. Gritzan

Michael said:
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.
 
M

Michael Sgier

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.
 
J

Jim Langston

Michael Sgier said:
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.
 
O

Old Wolf

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

CJoystickManager::CJoystickManager
{
}

Should be:

CJoystickManager::CJoystickManager()
{
}
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top