G
Generic Usenet Account
Hi,
I am passing a container type (e.g. list<int>) to a function template
but I am getting a compiler error when I try to declare an iterator
for that type in the function. However, I am able to invoke begin()
and end() without any problem. Is there a way to declare an iterator
for the container type? Sample code follows.
Thanks,
Ramesh
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
#include <iostream>
#include <list>
using namespace std;
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
template<typename T>
void
access_the_iterator(T& collection)
{
while(collection.begin() != collection.end())
{
cout << "In the loop\n";
}
//T::iterator iter;
// ** Compiler error upon uncommenting **
}
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
main()
{
list<int> coll;
access_the_iterator(coll);
return 0;
}
I am passing a container type (e.g. list<int>) to a function template
but I am getting a compiler error when I try to declare an iterator
for that type in the function. However, I am able to invoke begin()
and end() without any problem. Is there a way to declare an iterator
for the container type? Sample code follows.
Thanks,
Ramesh
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
#include <iostream>
#include <list>
using namespace std;
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
template<typename T>
void
access_the_iterator(T& collection)
{
while(collection.begin() != collection.end())
{
cout << "In the loop\n";
}
//T::iterator iter;
// ** Compiler error upon uncommenting **
}
//////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////
main()
{
list<int> coll;
access_the_iterator(coll);
return 0;
}