Confusing template error...

Jeffrey Holle jeff.holle@verizon.net
Sun Oct 24 02:01:00 GMT 2004


If I were trying this, I'd follow the "note" suggestion in gcc's error 
message.  That is:
   typename std::vector<typename type>::const_iterator pos;

James Urquhart wrote:
> Unfortunatly, the solution does not seem to work.
> 
> "std::vector<typename type>::const_iterator pos;"
> Gives me the errors:
> error: template argument 1 is invalid
> error: template argument 2 is invalid
> error: expected `;' before '::' token
> 
> I also tried doing :
> "typename std::vector<type>::const_iterator pos;"
> As someone else suggested, but that gives me the same errors as previously.
> 
> On Mon, 18 Oct 2004 10:33:09 -0600, lrtaylor@micron.com
> <lrtaylor@micron.com> wrote:
> 
>>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.
>>
> 
> 



More information about the Gcc-help mailing list