473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Generic iterator declaration

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

template <typename Tn>
ostream& operator<<(ostream& out, vector<TnVV)
{
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)
Sep 26 '08 #1
2 2540
Hansel Stroem wrote:
Is this legitimate STL code ? Compiler seems not to like the iterator ...
No, it's not. It's missing a keyword or two.
>
template <typename Tn>
ostream& operator<<(ostream& out, vector<TnVV)
You should look into passing the vector by a reference to const:

... (ostream& out, vector<Tnconst& VV)
{
for ( vector<Tn>::iterator it = VV.begin(); it != VV.end(); ++it )
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 =
{
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)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 26 '08 #2
Victor Bazarov 写道:
>{
for ( vector<Tn>::iterator it = VV.begin(); it != VV.end(); ++it )
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.
Sep 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carlo Milanesi | last post by:
Let's say I want to write the following function, void f(const list<int> &l, const vector<int> &v) { cout << get_second(l) << '\n'; cout << get_second(v) << '\n'; cout << get_nth(l, 2) << '\n';...
5
by: music4 | last post by:
Greetings, I want to STL map class. But I don't know how to use iterator. Let me state my question by following small sample: map<int, int> mymap; // insert some <key,value> in mymap ...
4
by: John | last post by:
I have a function declaration that gives an error while compiling. Can anyone help me figure this one out? inline void create(const std::vector< myclass >& plist, std::vector< myclass...
4
by: KL | last post by:
Well, I got through those other hurdles, but now I am stuck with trying to get an iterator to work. I am having a problem with trying to iterate through the STL list container that I set up. I...
6
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
10
by: desktop | last post by:
I have read about input, output forward etc iterators. But if I make the following: int myints = {1,2,3,4,5,1,2,3,4,5}; std::vector<intmyvector (myints,myints+10); std::vector<int>::iterator...
3
by: Dave | last post by:
I'm calling string.Split() producing output string. I need direct access to its enumerator, but would greatly prefer an enumerator strings and not object types (as my parsing is unsafe casting...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
2
by: jimxoch | last post by:
Dear list, I have recently implemented a generic sequence searching template function, named single_pass_search, which is more generic than std::search and has better worst case complexity at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.