Static Member declaration GCC

-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 Hello, I tried to declare a boost:shared_ptr as a static member of a template function. If I compile the program with Visual Studio all are Ok. If I try to compile the code with gcc, gcc failed with: t1.cpp:71: error: too few template-parameter-lists t1.cpp:72: error: too few template-parameter-lists There is a small mistake in my code but I can't find the error. Can someone help me? Bye Bernd - ------------------ code ----------------------------- #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> template <class T> class SimpleSingleton { public: SimpleSingleton() { } ~SimpleSingleton() { } T * instance() { boost::mutex::scoped_lock sp_lock(inst_mutex); if (!as.get()) { boost::shared_ptr<T> temp(new T); as=temp; } return as.get(); } protected: static boost::shared_ptr<T>(as); static boost::mutex inst_mutex; }; class test { protected: test(void) { a_=0; } public: ~test(void) { } int Get(void) { return a_; } void Set(int a) { a_ = a; } protected: int a_; friend class SimpleSingleton<test>; }; boost::shared_ptr<test> SimpleSingleton<test>::as; boost::mutex SimpleSingleton<test>::inst_mutex; int main(void) { SimpleSingleton<test> t; t.instance()->Set(45); int b=t.instance()->Get(); return b; } - ------------------ code ----------------------------- - -- TRIOPTICS GmbH Bernd Martin Wollny Software Designer Hafenstrasse 39, 22880 Wedel/GERMANY phone / fax: +49 (0)4103 18006-26 /-20 e-mail: bm.wollny@trioptics.com All E-Mails from bm.wollny@trioptics.com are digital signed. If you get a unsigned E-Mail, this E-Mail are a fake. Look at http://www.gnupg.org . -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Cygwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDdKc4CjfVnTPD3b4RA+0HAKC4jcBEeYvc75ZqJj4q2cNALGFElwCfZANJ X2i8t+fFa5o/rQQyha0KDqs= =BUfl -----END PGP SIGNATURE-----

Bernd, this question should go to some C++ newsgroup, as it is only vaguely related to boost. Bernd Martin Wollny wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160
Hello, I tried to declare a boost:shared_ptr as a static member of a template function. If I compile the program with Visual Studio all are Ok. If I try to compile the code with gcc, gcc failed with:
t1.cpp:71: error: too few template-parameter-lists t1.cpp:72: error: too few template-parameter-lists
There is a small mistake in my code but I can't find the error.
Can someone help me?
You define members of a class template, which thus is a template declaration. You are thus missing a template-parameter-list, just as the compiler tells you:
boost::shared_ptr<test> SimpleSingleton<test>::as; boost::mutex SimpleSingleton<test>::inst_mutex;
should be: template <> boost::shared_ptr<test> SimpleSingleton<test>::as; template <> boost::mutex SimpleSingleton<test>::inst_mutex; Regards, Stefan

-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 Hello Stefan, thank you for your replay.
this question should go to some C++ newsgroup, as it is only vaguely related to boost. You are right, i will post it again to a C++ newsgroup.
boost::shared_ptr<test> SimpleSingleton<test>::as; boost::mutex SimpleSingleton<test>::inst_mutex;
should be:
template <> boost::shared_ptr<test> SimpleSingleton<test>::as; template <> boost::mutex SimpleSingleton<test>::inst_mutex;
The empty template parameter solved the compilation problem, but now there are a link error: /tmp/ccn0DQFJ.o:t1.cpp:(.text$_ZN15SimpleSingletonI4testE8instanceEv[SimpleSingleton<test>::instance()]+0x44): undefined reference to `SimpleSingleton<test>::inst_mutex' /tmp/ccn0DQFJ.o:t1.cpp:(.text$_ZN15SimpleSingletonI4testE8instanceEv[SimpleSingleton<test>::instance()]+0x5d): undefined reference to `SimpleSingleton<test>::as' /tmp/ccn0DQFJ.o:t1.cpp:(.text$_ZN15SimpleSingletonI4testE8instanceEv[SimpleSingleton<test>::instance()]+0xab): undefined reference to `SimpleSingleton<test>::as' /tmp/ccn0DQFJ.o:t1.cpp:(.text$_ZN15SimpleSingletonI4testE8instanceEv[SimpleSingleton<test>::instance()]+0x103): undefined reference to `SimpleSingleton<test>::as' bye Bernd - -- TRIOPTICS GmbH Bernd Martin Wollny Software Designer Hafenstrasse 39, 22880 Wedel/GERMANY phone / fax: +49 (0)4103 18006-26 /-20 e-mail: bm.wollny@trioptics.com All E-Mails from bm.wollny@trioptics.com are digital signed. If you get a unsigned E-Mail, this E-Mail are a fake. Look at http://www.gnupg.org . -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Cygwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDeE0SCjfVnTPD3b4RA5wZAJ9N4FIwom+TXJYDLdpad01CX8l7UgCgp67r x8vprpyxOZAbg5cNfyOwkNU= =Xejc -----END PGP SIGNATURE-----
participants (3)
-
Bernd Martin Wollny
-
John Maddock
-
Stefan Seefeld