I just wondered if the new C ++ 11 class member initializers in the class could be used to initialize the Singletons at compile time, which could be an acceleration for some Manager classes in my applications:
class CSingleton
{
public:
CSingleton(void) {}
~CSingleton(void) {}
static const CSingleton* GetInstance(void)
{
return Instance;
}
bool Foo1(int x);
bool Foo2(int y);
private:
static constexpr CSingleton *Instance = new CSingleton();
}
The problem is this:
Line of Instance declaration: error: invalid use of incomplete type 'class test::CSingleton'
First Line of class declaration: error: forward declaration of 'class test::CSingleton'
Is there a way to initialize Singletons at compile time with this or another approach?
[I use GCC4.7 on MacOSX10.7 (and Ubuntu) with the -std = C ++ 0x flag set]
source
share