I had a look at that example, but I'm sorry to say I didn't understand it
fully. The code later in this message works fine if I write
CConfig CConfig::m_instance = CConfig(); // 1
in any cpp-file, but not if write
CString CConfig::GetString() = "test"; // 2
As I'm starting to panic here, would you please state exactly what to with
my example below to make it work to use CConfig::GetString(); Do I really
have to use // 1 above?
class CConfig
{
private:
static CConfig m_instance;
CString m_string;
static CConfig& GetInstance();
public:
static CString GetString()
{
return m_instance.m_string;
};
CConfig();
~CConfig();
};
/Config.cpp
#include ".\config.h"
CConfig::CConfig()
{
m_string = "Test";
}
CConfig::~CConfig()
{
}
CConfig& CConfig::GetInstance()
{
return m_instance;
}
"Sharad Kala" <no******************@yahoo.com> wrote in message
news:2q*************@uni-berlin.de...
"Andy" <do**@spam.me> wrote in message 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)
Check this FAQ -
http://www.parashift.com/c++-faq-lit...html#faq-10.10
Sharad