c ++ Meyers singleton undefined reference

Mar*_*ney 0 c++ singleton

我有以下代码实现了基本的Meyers单音:

#ifndef _cConfigFile_HH
#define _cConfigFile_HH

class cConfigFile {
public:
  static cConfigFile& getInstance() {
    static cConfigFile instance;
    return instance;
  };
private:
  cConfigFile();
};

#endif
Run Code Online (Sandbox Code Playgroud)

我的编译器不允许我编译它,给出以下错误:

/include/cConfigFile.hh:7: undefined reference to `cConfigFile::cConfigFile()'
Run Code Online (Sandbox Code Playgroud)

从错误我明白我需要在.cpp文件中声明"实例",但我无法声明cConfigFile :: instance,因为编译器说:

'cConfigFile cConfigFile :: instance'不是静态的

我究竟做错了什么??我迷路了

Edw*_*nge 11

你忘了实现你的构造函数了.