This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]