Templates gcc 3.4
From: Simon White (s_a_white_at_email.com)
Date: 12/09/04
- Next message: <$bracket$>: "NIA"
- Previous message: Peter Koch Larsen: "Re: Is this good style of C++?"
- Next in thread: Victor Bazarov: "Re: Templates gcc 3.4"
- Reply: Victor Bazarov: "Re: Templates gcc 3.4"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 09 Dec 2004 18:58:39 GMT
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?
- Next message: <$bracket$>: "NIA"
- Previous message: Peter Koch Larsen: "Re: Is this good style of C++?"
- Next in thread: Victor Bazarov: "Re: Templates gcc 3.4"
- Reply: Victor Bazarov: "Re: Templates gcc 3.4"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|