Confusing template error...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux