This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Confusing template error...
- From: James Urquhart <jamesu at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 21 Oct 2004 13:32:54 +0100
- Subject: Re: Confusing template error...
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=dFnrWob8O1U6Lcg4KtDA+8nql3t3tYm/Sw5SzfrtNO+G1aUYlQY3sME0Jyzjpuwz5YpFEkaS35Pbtc8YG4wj8QXJwtIMIDXoZTScMiZtjDcrAi0sWxpWQ+5YXbZ6yMZHcPv+HTAmgx/6KoU4MLNMyTuU3SQF/EK9iPxTGxurCXE=
- References: <363801FFD7B74240A329CEC3F7FE4CC4030963B4@ntxboimbx07.micron.com> <f233346204101904401de686ed@mail.gmail.com>
- Reply-to: James Urquhart <jamesu at gmail dot com>
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.
>