F
Francesco Monica
Hello.
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?
Is correct to initialize private data members in that manner?
(With a non-template "Singleton" no errors were produced)
I wish to test the code with the new gcc 3.3.2, but I have no ways to
install it by now...
Can you give me some suggestions?
Thank you in advance.
Francesco.
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?
Is correct to initialize private data members in that manner?
(With a non-template "Singleton" no errors were produced)
I wish to test the code with the new gcc 3.3.2, but I have no ways to
install it by now...
Can you give me some suggestions?
Thank you in advance.
Francesco.