Problème de link dans un singleton
Bonjour,
voici une implémentation du singleton :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| template<typename T>
class Singleton
{
private: static T instance;
private: Singleton()
{
};
private: Singleton(const T&);
private: T& operator=(const T&);
public: static T& getInstance()
{
return instance;
}
};
int main(void)
{
int& n1 = Singleton<int>::getInstance();
return 0;
} |
Mais le link génère l'erreur :
Code:
1 2
| /tmp/ccWMzoqa.o: In function `Singleton<int>::getInstance()':
test.cpp:(.text._ZN9SingletonIiE11getInstanceEv[Singleton<int>::getInstance()]+0x4): undefined reference to `Singleton<int>::instance' |
Où est l'erreur ?
Merci .