T
Tim Clacy
Would some kind soul suggest a pre-processor test for the C++ language
revision whereby class static variables were specified to refer to the same
instance? Specifically, the following Singleton template will work with some
compilers but not with older ones (because every module that includes the
header gets its own unique static 'instance'):
template<typename T>
struct Singleton
{
static T& Instance() { static T instance; return instance; }
private:
Singleton() { }
~Singleton() { }
Singleton(const Singleton& rhs);
Singleton& operator=(const Singleton& rhs);
};
Can the standard pre-processor definition __STDC_VERSION__ be tested? If so,
for what value?
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
:
#endif
Regards
Tim
revision whereby class static variables were specified to refer to the same
instance? Specifically, the following Singleton template will work with some
compilers but not with older ones (because every module that includes the
header gets its own unique static 'instance'):
template<typename T>
struct Singleton
{
static T& Instance() { static T instance; return instance; }
private:
Singleton() { }
~Singleton() { }
Singleton(const Singleton& rhs);
Singleton& operator=(const Singleton& rhs);
};
Can the standard pre-processor definition __STDC_VERSION__ be tested? If so,
for what value?
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
:
#endif
Regards
Tim