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: Thomas Maeder
Subject: Re: A problem with the g++ and template function
Date: Mon, 31 Mar 2008 22:28:28 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

gx <namespace.gx@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]