public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Confusing template error...
@ 2004-10-18 16:33 lrtaylor
       [not found] ` <f233346204101904401de686ed@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: lrtaylor @ 2004-10-18 16:33 UTC (permalink / raw)
  To: jamesu, gcc-help

Try this:

      std::vector<typename type>::const_iterator pos;

Thanks,
Lyle


-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of James Urquhart
Sent: Saturday, October 16, 2004 4:07 PM
To: gcc-help@gcc.gnu.org
Subject: Confusing template error...

Hi there,

I was wondering if anyone has encountered this rather bizzare syntax
error before.

The code is as follows (NOTE: this is inside a class { }) :

   template <class type>
   inline OutputStream & operator << (OutputStream & out, const
std::vector<type> &v)
   {
      std::vector<type>::const_iterator pos;
      pos = v.begin() ;
      while (pos != v.end())
      {
         out << *pos++ ;
      }
      return out ;
   }

(using the good ol' STL vector)

in the "const_iterator" line, GCC claims :
error: expected `;' before "pos"

in addition, every time the "<<" operator is used, GCC claims :
error: dependent-name ` std::vector<type,std::allocator<_CharT>
>::const_iterator' is parsed as a non-type, but instantiation yields a
type
note: say `typename std::vector<type,std::allocator<_CharT>
>::const_iterator' if a type is meant

(basically referring again to that line)
If i remove the "pos;" at the end of the line, gcc seems to accept it
- but then i don't have a "pos" variable, which is pretty useless.


Now onto the next problem...

With this code (again, in a class { }) :

template <class type>
   inline InputStream & operator >> (InputStream & in, std::vector<type>
&v)
   {
      std::vector<type>::iterator pos = v.begin() ;
      while (pos != v.end())
      {
         in >> *pos++ ;
      }
      return in ;
   }

Every time ">>" is used on this class, GCC claims on the "iterator"
line:
error: dependent-name ` std::vector<type,std::allocator<_CharT>
>::iterator' is parsed as a non-type, but instantiation yields a type
note: say `typename std::vector<type,std::allocator<_CharT>
>::iterator' if a type is meant.



And the gcc variant :
gcc version 3.4.2  (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-8.7.6.5)

Thanks for any help.

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Confusing template error...
@ 2004-10-16 22:06 James Urquhart
  0 siblings, 0 replies; 4+ messages in thread
From: James Urquhart @ 2004-10-16 22:06 UTC (permalink / raw)
  To: gcc-help

Hi there,

I was wondering if anyone has encountered this rather bizzare syntax
error before.

The code is as follows (NOTE: this is inside a class { }) :

   template <class type>
   inline OutputStream & operator << (OutputStream & out, const
std::vector<type> &v)
   {
      std::vector<type>::const_iterator pos;
      pos = v.begin() ;
      while (pos != v.end())
      {
         out << *pos++ ;
      }
      return out ;
   }

(using the good ol' STL vector)

in the "const_iterator" line, GCC claims :
error: expected `;' before "pos"

in addition, every time the "<<" operator is used, GCC claims :
error: dependent-name ` std::vector<type,std::allocator<_CharT>
>::const_iterator' is parsed as a non-type, but instantiation yields a
type
note: say `typename std::vector<type,std::allocator<_CharT>
>::const_iterator' if a type is meant

(basically referring again to that line)
If i remove the "pos;" at the end of the line, gcc seems to accept it
- but then i don't have a "pos" variable, which is pretty useless.


Now onto the next problem...

With this code (again, in a class { }) :

template <class type>
   inline InputStream & operator >> (InputStream & in, std::vector<type> &v)
   {
      std::vector<type>::iterator pos = v.begin() ;
      while (pos != v.end())
      {
         in >> *pos++ ;
      }
      return in ;
   }

Every time ">>" is used on this class, GCC claims on the "iterator" line:
error: dependent-name ` std::vector<type,std::allocator<_CharT>
>::iterator' is parsed as a non-type, but instantiation yields a type
note: say `typename std::vector<type,std::allocator<_CharT>
>::iterator' if a type is meant.



And the gcc variant :
gcc version 3.4.2  (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-8.7.6.5)

Thanks for any help.

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

end of thread, other threads:[~2004-10-24  2:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-18 16:33 Confusing template error lrtaylor
     [not found] ` <f233346204101904401de686ed@mail.gmail.com>
2004-10-21 12:32   ` James Urquhart
2004-10-24  2:01     ` Jeffrey Holle
  -- strict thread matches above, loose matches on Subject: below --
2004-10-16 22:06 James Urquhart

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).