455,128 Members | 1,206 Online
Need help? Post your question and get tips & solutions from a community of 455,128 IT Pros & Developers. It's quick & easy.

# Iterator-Template problem

 P: n/a Hi, I have this code #include #include #include using namespace std; template & v){ typedef typename vector::iterator i; for (i = v.begin();i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector
7 Replies

 P: n/a * ng************@gmail.com: Hi, I have this code #include #include #include using namespace std; template & v){ typedef typename vector::iterator i; for (i = v.begin();i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector

 P: n/a ng************@gmail.com wrote: Hi, I have this code #include #include #include using namespace std; template & v){ typedef typename vector::iterator i; typename vector::const_iterator i; -- Ian Collins. Mar 18 '07 #3

 P: n/a ng************@gmail.com wrote: Hi, I have this code #include #include #include using namespace std; template & v){ typedef typename vector::iterator i; Here, you create a typedef for vector::iterator, and call this type 'i'. for (i = v.begin();i != v.end(); ++i) Here, you are trying to assign a value to a type, similar to if you did: for (int = 0; int != v.size(); ++int) You need to declare a variable of that type before you can use it. For clarity, I would call the typedef 'it': typedef typename vector::iterator It; for (It i = v.begin(); i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector

 P: n/a On 18 Mar 2007 14:47:23 -0700 in comp.lang.c++, ng************@gmail.com wrote, > typedef typename vector::iterator i; for (i = v.begin();i != v.end(); ++i) "i" is the name of the type. It is not a variable. A type cannot appear to the left of =. You need an actual variable there. Mar 18 '07 #5

 P: n/a Thanks everyone. I have tried to change the code as suggested #include #include #include using namespace std; template & v){ typedef typename vector::iterator It; for (It i = v.begin();i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector::__normal_iterator(const __gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter = const int*, _Ite rator = int*, _Container = std::vector

 P: n/a ng************@gmail.com wrote: Thanks everyone. I have tried to change the code as suggested #include #include #include using namespace std; template & v){ typedef typename vector::iterator It; for (It i = v.begin();i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector

 P: n/a On Mar 18, 9:48 pm, Ian Collins #include #include using namespace std; template & v){ typedef typename vector::iterator It; for (It i = v.begin();i != v.end(); ++i) cout << (*i) << " "; cout << endl; } int main(){ vector

### This discussion thread is closed

Replies have been disabled for this discussion.