This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
linking error with static templated member
- From: "Akos Rajna" <akimaki23 at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 28 Jan 2008 15:13:36 +0100
- Subject: linking error with static templated member
Hi,
i'v tried to search for a solution everywhere without a luck so i hope
you guys can help. i have the following singleton template and it
works fine with vc++ however not with gcc.
template<class O> class SingletonInstance {
O* inst;
public:
SingletonInstance() {
inst = NULL;
}
~SingletonInstance() {
finalize();
}
O* instance() {
if (inst == NULL)
inst = new O();
return inst;
}
void finalize() {
if (inst != NULL)
delete inst;
inst = NULL;
}
};
template<class O> class Singleton {
public:
static SingletonInstance<O> singleton;
public:
Singleton() {
}
static O* instance() {
return singleton.instance();
}
static void finalize() {
singleton.finalize();
}
};
class NetworkManager : public Singleton<NetworkManager>
{
private:
NetworkManager();
~NetworkManager();
friend class SingletonInstance<NetworkManager>;
};
-----------------
template<> SingletonInstance<NetworkManager>
Singleton<NetworkManager>::singleton;
-----------------
and the linker is saying that Singleton<NetworkManager>::singleton is undefined
thanks in advance