S
Simon White
I've just upgraded to gcc 3.4 resulting in problems in some template
code I have. The code shown below is a simplified version of what we
are using to wrap the creation of singletons.
#include <new>
template <class T>
class foo
{
public:
static T& Instance();
private:
static T* _me;
static char _buildHere[];
};
template <class T>
inline T& foo<T>::Instance()
{
if (0 == _me)
_me = new(_buildHere) T;
return *_me;
}
class bar
{
};
bar* foo< bar >::_me = 0;
char foo< bar >::_buildHere[sizeof(bar)];
bar &t = foo<bar>::Instance ();
int main ()
{
return 0;
}
It complains about:
test.cpp:26: error: too few template-parameter-lists
test.cpp:26: error: expected `,' or `;' before '=' token
test.cpp:27: error: too few template-parameter-lists
Doing a search for information appears that we need to add template<> to
get the error to disappear, however doing so now causes a link problem
claiming the _buildHere symbol is undefined (_me seems to be ok). I
also tried this modified code in gcc 3.3 resulting in the same problem.
Is this a problem with the code and if so any ideas on how to fix it?
code I have. The code shown below is a simplified version of what we
are using to wrap the creation of singletons.
#include <new>
template <class T>
class foo
{
public:
static T& Instance();
private:
static T* _me;
static char _buildHere[];
};
template <class T>
inline T& foo<T>::Instance()
{
if (0 == _me)
_me = new(_buildHere) T;
return *_me;
}
class bar
{
};
bar* foo< bar >::_me = 0;
char foo< bar >::_buildHere[sizeof(bar)];
bar &t = foo<bar>::Instance ();
int main ()
{
return 0;
}
It complains about:
test.cpp:26: error: too few template-parameter-lists
test.cpp:26: error: expected `,' or `;' before '=' token
test.cpp:27: error: too few template-parameter-lists
Doing a search for information appears that we need to add template<> to
get the error to disappear, however doing so now causes a link problem
claiming the _buildHere symbol is undefined (_me seems to be ok). I
also tried this modified code in gcc 3.3 resulting in the same problem.
Is this a problem with the code and if so any ideas on how to fix it?