Question about vector iterator in template functions?

You need to say typename vector::iterator it On another note, you're passing vector s by value. That means the entire vector gets copied in the function call void Show(vector const &myvec) and using const_iterator would be wiser.

You need to say typename vector::iterator it. On another note, you're passing vectors by value. That means the entire vector gets copied in the function call.

Void Show(vector const &myvec) and using const_iterator would be wiser.

2 If he passes a const ref, you need to also tell him to use a const_iterator. – Erik Mar 4 at 11:08 @Erik: absolutely right, updated my post. – larsmans Mar 4 at 11:09 thanks for the tip.

– Rafael S. Calsaverini Mar 4 at 11:22.

You need this: typename vector::iterator it; This tells the compiler that vector::iterator should be treated as a type, something it can't assume since iterator is dependent on what T is.

Some compilers have problems detecting what is a member name and what is a type name, when inside templates. Try writing something like this in the first line of your template function body. Typename vector::iterator it.

1 Correct, but it is not really a compiler problem. The C++ Standard mandates that the compiler treat a dependent name in a template as a member and not a type, unless typename is used. – decltype Mar 4 at 11:11 1 It's not "some compilers".

The grammar simply does not allow it. "Some compilers" can double-guess programmer by retrying with typename if parsing fails without it and thus compiling some incorrect cases. – Jan Hudec Mar 4 at 11:18 You are right.

Point taken! – CygnusX1 Mar 4 at 11:29.

Maybe it works using typename vector::iterator it; Your compiler cannot know that there is an inner class iterator.

In the first instance the parameter, although it uses a template, is not a template, it is a fully defined class (vector) In the latter instance the parameter is a template on type T and thus requires typename.

You need to say typename vector::iterator it .

And InputIterator is a template parameter. Formal type parameters InputIterator and T. Correctly be substituted for the formal template parameters.

Formal template parameter InputIterator. Or of type double. Instantiated with any type that satisfies those requirements.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions