This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Confusing template error...
- From: lrtaylor at micron dot com
- To: <jamesu at gmail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Mon, 18 Oct 2004 10:33:09 -0600
- Subject: RE: Confusing template error...
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.