This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Confusing template error...
- From: James Urquhart <jamesu at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 16 Oct 2004 23:06:51 +0100
- Subject: Confusing template error...
- Domainkey-signature: a=rsa-sha1; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=Xj4Jj9dOp4xHd55hLa/I9J8ySCKlwu3MvFtsSffVRAhrnX9v6c2/Vlab9BsP/qvjV43EDSaT7lsGI1D6WX+un47fQ36JXY2FR7Ad/+13dktj4GLq6GiaLg1K6k37pKRdYYjvX+fwC7VeyxZOtvYfzQWCV29RokMboTig4hJ4iEE
- Reply-to: James Urquhart <jamesu at gmail dot com>
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.