Sign in to follow this  
Mizipzor

Unknown compiler errors

Recommended Posts

Mizipzor    247
I get these error messages:
------ Build started: Project: TileSystem, Configuration: Debug Win32 ------

Linking...
AsciiMap.obj : error LNK2019: unresolved external symbol "protected: __thiscall SdlHandle::SdlHandle(void)" (??0SdlHandle@@IAE@XZ) referenced in function "public: static class SdlHandle * __cdecl SdlHandle::GetInstance(void)" (?GetInstance@SdlHandle@@SAPAV1@XZ)
Game.obj : error LNK2001: unresolved external symbol "protected: __thiscall SdlHandle::SdlHandle(void)" (??0SdlHandle@@IAE@XZ)
AsciiMap.obj : error LNK2001: unresolved external symbol "protected: static class SdlHandle * SdlHandle::m_pInstance" (?m_pInstance@SdlHandle@@1PAV1@A)
Game.obj : error LNK2019: unresolved external symbol "protected: static class SdlHandle * SdlHandle::m_pInstance" (?m_pInstance@SdlHandle@@1PAV1@A) referenced in function __ehhandler$?GetInstance@SdlHandle@@SAPAV1@XZ
Debug/TileSystem.exe : fatal error LNK1120: 2 unresolved externals

I dont get any line numbers so I dont really know where the problem is. And I dont really know what all that means so I dont know where to start looking but it seems that somehow some class is accessing the my sdl handles protected stuff... Anyone knows whats wrong?

Share this post


Link to post
Share on other sites
sphinx23    188
You try to use some methods and static variables, but you don't seem to define them anywhere, i.e. you have to define SdlHandle::SdlHandle and SdlHandle::m_pInstance.

Share this post


Link to post
Share on other sites
nmi    978
Those are linker errors.
Often you get them when using global objects.
The object is declared somewhere like this:

extern GlobalType globalObject;

But there is no instance of that object, which must be provided in exactly one source file like this:

GlobalType globalObject;


Also static members of classes must be used like this.

Share this post


Link to post
Share on other sites
Mizipzor    247
There are no global objects. But I do have some functions and variables set to static in one class. But those are defined:

SdlHandle.h

class SdlHandle {
protected:
// singleton pattern
static SdlHandle* m_pInstance;
SdlHandle( void );

public:
//
// Singleton pattern, retrieve the pointer to the one and only instance of the class
// If no pointer exists, the class is created
//
static SdlHandle* GetInstance( void ) {
if ( !m_pInstance )
m_pInstance = new SdlHandle();
return m_pInstance;
};
};



I cut out the unimportant...

I looked through the files stated in the error messages, but I couldnt see anything wrong there... This is the first time I try to do something static (I want to be sure only one instance of the class exists and that its shared among the other classes) so Ive probarbly messed something up.

Share this post


Link to post
Share on other sites
sphinx23    188
You have to define the static variables outside of the class, e.g.:

class X
{
static int Y;
};
int X::Y = 0;


And the constructor (SdlHandle::SdlHandle) seems to have to body (at least not in the code you posted), you also have to define it somewhere, like:

SdlHandle::SdlHandle( void )
{
// Your code goes here...
}

Share this post


Link to post
Share on other sites
Stephen R    721
Two things. It seems like you haven't defined the constructor or the static Instance var. Try this:


////////////////////////////////
//sdlhandle.hpp
class SdlHandle {
protected:
// singleton pattern
static SdlHandle* m_pInstance;
SdlHandle( void ) { }; //define the constructor

public:
//
// Singleton pattern, retrieve the pointer to the one and only instance of the class
// If no pointer exists, the class is created
//
static SdlHandle* GetInstance( void ) {
if ( !m_pInstance )
m_pInstance = new SdlHandle();
return m_pInstance;
};
};
//////////////////////////////////
//sdlhandle.cpp
#include "sdlhandle.hpp"
SdlHandle* SdlHandle::m_pInstance = 0; //define the static var. this is
//required with all static vars.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this