A problem with templates and static array initializers...

corey taylor corey.taylor@gmail.com
Wed Jan 26 21:39:00 GMT 2005


(I sent this to Joseph only.)

Joseph,

You need to declare the explicit template specialization with the
templat<> keyword:

template<class T>
class Base
{
public:
       struct _BaseStruct
       {
               int x;
               int y;
       };

private:
       static const _BaseStruct _table[];
};

class Derived : public Base<Derived>
{
};

template<> const Base<Derived>::_BaseStruct Base<Derived>::_table[] =
{
       { 1, 2 },
       { 4, 5 },
};


corey


On Wed, 26 Jan 2005 14:19:14 -0700, Joseph Galbraith <galb@vandyke.com> wrote:
> I have this code (below) which compiles with
> older versions of g++, Visual C++ and xlC,
> and looks correct to me.
> 
> But, 3.4.2 is rejecting it.
> 
> Now I know all those compilers (and me too)
> could (probably) be wrong and the code is
> wrong...
> 
> So the question is, is the following code
> incorrect, and if so, how do I fix it.
> 
> template<class T>
> class Base
> {
> public:
>          struct _BaseStruct
>          {
>                  int x;
>                  int y;
>          };
> 
> private:
>          static const _BaseStruct _table[];
> };
> 
> class Derived : public Base<Derived>
> {
> };
> 
> const Base<Derived>::_BaseStruct Base<Derived>::_table[] =
> {
>          { 1, 2 },
>          { 4, 5 },
> };
> 
> It fails to compile with this error:
> 
> x3.cpp:19: error: too few template-parameter-lists
> x3.cpp:19: error: expected `,' or `;' before '=' token
> 
> [galb@random temp]$ gcc --version
> gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)1
> 
> Thanks,
> 
> Joseph
>



More information about the Gcc-help mailing list