Templates gcc 3.4

From: Simon White (s_a_white_at_email.com)
Date: 12/09/04


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?



Relevant Pages

  • Re: MUCH simpler program displaying same behavior
    ... The above didn't work for me with GCC 3.4 or como. ... template ... static char const* const a; ... If anyone knows why isn't a definition as well as a declaration, ...
    (comp.lang.cpp)
  • Re: Templates gcc 3.4
    ... Simon White wrote: ... > also tried this modified code in gcc 3.3 resulting in the same problem. ... specialised template members. ...
    (comp.lang.cpp)
  • gcc 3.3.1 to 3.4.1: template friend operator problem
    ... Now I've installed gcc 3.4.1 and the ... My guess is that the declaration of template friend operator ... </GCC 3.4.1 error message> ...
    (alt.comp.lang.learn.c-cpp)
  • Re: GCC BUG?
    ... The only reason I thought it was that my last go around with GCC was ... when template support was pretty terrible. ... Does GCC typically show template compilation errors? ...
    (comp.os.linux.development.apps)
  • Re: GCC BUG?
    ... The only reason I thought it was that my last go around with GCC was ... when template support was pretty terrible. ... Does GCC typically show template compilation errors? ...
    (comp.os.linux.development.apps)