help-gplusplus
[Top][All Lists]
Advanced

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

Re: A problem with the g++ and template function


From: gx
Subject: Re: A problem with the g++ and template function
Date: Mon, 31 Mar 2008 14:10:24 -0700 (PDT)
User-agent: G2/1.0

Indeed, I've tried what it told me, but unfortunately with some
mistakes.
No matter. Thank you a lot for your reply.

On 31 Bře, 21:28, Thomas Maeder <mae...@glue.ch> wrote:
> gx <namespace...@gmail.com> writes:
>
> > template<class T> bool find0(const std::vector<T> &v){
> >         for(std::vector<T>::const_iterator it=v.begin(); it!=v.end(); +
> > +it){
> >                 if(!*it)
> >                         return true;
> >         }
> >         return false;
> > }
>
> > I believe that the problem is in the definition of template function.
>
> > When I try to compile a source code with g++/minigw32-g++ I obtain
> > this output:
>
> > $ g++ -Wall -pedantic pokus2.cpp
> > pokus2.cpp: In function 'bool find0(const std::vector<T,
> > std::allocator<_CharT> >&)':
> > pokus2.cpp:17: error: expected `;' before 'it'
> > pokus2.cpp:17: error: 'it' was not declared in this scope
> > pokus2.cpp: In function 'bool find0(const std::vector<T,
> > std::allocator<_CharT> >&) [with T = double]':
> > pokus2.cpp:38:   instantiated from here
> > pokus2.cpp:17: error: dependent-name
> > 'std::vector<T,std::allocator<_CharT> >::const_iterator' is parsed as
> > a non-type, but instantiation yields a type
> > pokus2.cpp:17: note: say 'typename
> > std::vector<T,std::allocator<_CharT> >::const_iterator' if a type is
> > meant
>
> > I would gladly welcome your replies.
>
> Well, the error message says it all. have you tried doing what it
> tells you to?
>
> I.e.
>
> for (typename std::vector<T>::const_iterator it = v.begin();
>      it!=v.end();
>      ++it)
>
> If you don't write typename, the compiler has to assume that
> const_iterator names something that is not a type.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]