public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* A problem with templates and static array initializers...
@ 2005-01-26 21:19 Joseph Galbraith
  2005-01-26 21:39 ` corey taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Joseph Galbraith @ 2005-01-26 21:19 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: A problem with templates and static array initializers...
  2005-01-26 21:19 A problem with templates and static array initializers Joseph Galbraith
@ 2005-01-26 21:39 ` corey taylor
  0 siblings, 0 replies; 2+ messages in thread
From: corey taylor @ 2005-01-26 21:39 UTC (permalink / raw)
  To: gcc-help

(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
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-01-26 21:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-26 21:19 A problem with templates and static array initializers Joseph Galbraith
2005-01-26 21:39 ` corey taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).