A
Andy
I'm trying to make a Config-class that has only one instance, as the code
below states. However, when I try to use the instance with
CConfig::GetInstance() in another .cpp-file I get a link error:
StaticTest error LNK2001: unresolved external symbol "private: static class
CConfig CConfig::m_instance" (?m_instance@CConfig@@0V1@A)
Why is this?
//Config.h
class CConfig
{
private:
static CConfig m_instance;
public:
static CConfig& GetInstance();
CConfig();
~CConfig();
};
/Config.cpp
include "StdAfx.h"
#include ".\config.h"
CConfig::CConfig()
{
}
CConfig::~CConfig()
{
}
CConfig& CConfig::GetInstance()
{
return m_instance;
}
below states. However, when I try to use the instance with
CConfig::GetInstance() in another .cpp-file I get a link error:
StaticTest error LNK2001: unresolved external symbol "private: static class
CConfig CConfig::m_instance" (?m_instance@CConfig@@0V1@A)
Why is this?
//Config.h
class CConfig
{
private:
static CConfig m_instance;
public:
static CConfig& GetInstance();
CConfig();
~CConfig();
};
/Config.cpp
include "StdAfx.h"
#include ".\config.h"
CConfig::CConfig()
{
}
CConfig::~CConfig()
{
}
CConfig& CConfig::GetInstance()
{
return m_instance;
}