Jump to content
  • Advertisement
Sign in to follow this  
d1rk

[solved][c++] undefined reference to... errors

This topic is 3670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I compile my project with dev-c++ or code blocks(I didn't try other compilers) it gives lots of undefined reference errors for my logger class. My logger class is made a singleton by inhereting from a singleton class: what am I doing wrong?
[source="cpp"]
template <class stclass>
class singleton
{
  static stclass* stpointer;

  protected:
  singleton()
  {
    stpointer = 0;
  }
  ~singleton()
  {
    delete stpointer;
  }

  public:
  static stclass* getstpointer()
  {
  if (stpointer == 0)
  {
    stpointer = new stclass;
  }
  return stpointer;
  }
};

class loggerc: public singleton<loggerc>
{
  void addmessage(string);
};

class something
{
  loggerc* logger;

  something()
  {
    logger = loggerc::getstpointer();
  }
  dosomething()
  {
    logger->addmessage("I've added a message to the logger");
  }
};


Errors:
::getstpointer()]+0x37)||undefined reference to `singleton<loggerc>::stpointer'|
::getstpointer()]+0x9e)||undefined reference to `singleton<loggerc>::stpointer'|
::getstpointer()]+0xa3)||undefined reference to `singleton<loggerc>::stpointer'|

.objs\logger.o:logger.cpp:(.text+0x16b)||undefined reference to `singleton<loggerc>::singleton()'|
.objs\logger.o:logger.cpp:(.text+0x2cf)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0x341)||undefined reference to `singleton<loggerc>::singleton()'|
.objs\logger.o:logger.cpp:(.text+0x4a5)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0x517)||undefined reference to `singleton<loggerc>::singleton()'|
.objs\logger.o:logger.cpp:(.text+0x67a)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0x6ed)||undefined reference to `singleton<loggerc>::singleton()'|
.objs\logger.o:logger.cpp:(.text+0x850)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0x9d9)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0xa03)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0xb73)||undefined reference to `singleton<loggerc>::~singleton()'|
.objs\logger.o:logger.cpp:(.text+0xb9d)||undefined reference to `singleton<loggerc>::~singleton()'|
[Edited by - d1rk on November 30, 2008 7:37:09 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by d1rk
My logger class is made a singleton by inhereting from a singleton class

That sounds horrible.

Quote:
Original post by d1rk
static stclass* stpointer;

If my memory serves me right, this is only a declaration, not a definition. You have to define stpointer somewhere.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!