I know there are a million questions and answers about Singletons, but I just can't find a solution to this. So risking negative votes, here is my problem:
I want to use this singleton implementation from Andrei Alexandrescu 'Modern C ++ Design:
Title:
class Singleton { static Singleton& Instance(); private: Singleton(){}; Singleton(const Singleton&){}; Singleton& operator=(const Singleton&){}; ~Singleton(){}; };
implementation:
#include "s.hh" Singleton& Singleton::Instance() { static Singleton instance; return instance; }
Test:
#include "s.hh" int main(void) { Singleton& single = Singleton::Instance(); return 0; }
Now,
$g++ A.cc s.cc && ./a.out In file included from A.cc:1:0: s.hh: In function 'int main()': s.hh:3:19: error: 'static Singleton& Singleton::Instance()' is private static Singleton& Instance(); ^ A.cc:6:42: error: within this context Singleton& single = Singleton::Instance(); ^
What is wrong with that? I am stuck...
source share