linking error with static templated member

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux