I have a strange (or maybe not) error with the following code:
template<typename T>
class Registrer {
public:
Registrer() {
Registry::register(T::instance);
}
};
template<typename T>
class RegisteringClass {
private:
static const Registrer<T> REGISTRER;
public:
RegisteringClass () { Q_UNUSED(REGISTRER); }
static const WhatEver *instance() { static T INSTANCE; return &INSTANCE; }
};
template<typename T>
const Registrer<T> RegisteringClass<T>::REGISTRER;
class Something : public WhatEver, RegistringClass<Something> {
}
When the method instanceis in the template, I got the following error (gcc)
error: 'static const WhatEver* RegisteringClass<T>::instance() [with T = Something]' is inaccessible
static const WhatEver*instance() { static T INSTANCE; return &INSTANCE; }
error: within this context
Registry::register(T::instance);
In instantiation of 'static const WhatEver* RegisteringClass<T>::instance() [with T = Something]':
If instance()located in Something, everything is in order.
Did I miss some syntactic subtleties? Or is this a template limitation?
source
share