"Francesco Monica" <fmonica@ce.unipr.it> wrote...
This (example) code will compile correctly with gcc <= 3.3.0, but doesn't
compile with gcc 3.3.1 (under linux):
-------------------------------------------------------------
template < typename T >
class Singleton
{
private:
Singleton() {}
static Singleton instance;
public:
static Singleton& getInstance() { return instance; }
};
template < typename T > Singleton<T> Singleton<T>::instance;
Singleton<int>& a = Singleton<int>::getInstance();
--------------------------------------------------------------
This is the error returned by gcc:
test.cc: In instantiation of `Singleton<int> Singleton<int>::instance':
test.cc:9: instantiated from `static Singleton<T>&
Singleton<T>::getInstance() [with T = int]'
test.cc:15: instantiated from here
test.cc:5: error: `Singleton<T>::Singleton() [with T = int]' is private
test.cc:12: error: within this context
Btw, the code also works with the "Test Drive Comeau C++ Online"...
Did I make some errors?
Not that I can see.
Is correct to initialize private data members in that manner?
(With a non-template "Singleton" no errors were produced)
It's fine.
I wish to test the code with the new gcc 3.3.2, but I have no ways to
install it by now...
I believe some readers of this newsgroup can help, I am not one of
them, unfortunately. Have you tried gnu.g++.* newsgroups?
Can you give me some suggestions?
Contact the GNU GCC Project, they may have an idea. It does look
like a regression from the earlier version.
Victor
.