Generic iterator declaration

H

Hansel Stroem

Is this legitimate STL code ? Compiler seems not to like the iterator ...

template <typename Tn>
ostream& operator<<(ostream& out, vector<Tn> VV)
{
for ( vector<Tn>::iterator it = VV.begin(); it != VV.end(); ++it )
{
out << (*it);
}
return out << std::endl;
}


%icc BS.cc
BS.cc(151): error: expected a ";"
for ( vector<Tn>::iterator it = VV.begin(); it != VV.end(); ++it )
^

BS.cc(151): error: identifier "it" is undefined
for ( vector<Tn>::iterator it = VV.begin(); it != VV.end(); ++it )
^

compilation aborted for BS.cc (code 2)
 
Ä

书呆彭

Victor Bazarov 写é“:
Has to be

for ( typename vector<Tn>::iterator it = ...

(or, if you decide to pass the vector by a const ref,

for ( typename vector<Tn>::const_iterator it =

right.
use typename here.
see the standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top