I have some kind of weird problem with templates. When trying to pass a parameterized iterator, it complains that no function can be found. Code snippet here, forget about the functionality, it uses a link to the templatized iterator that interests me
#include <list>
#include <iostream>
template<typename T>
void print_list_element(typename std::list<T>::iterator& it){
std::cout << *it << std::endl;
}
int main() {
std::list<int> theList;
theList.push_back(1);
std::list<int>::iterator it = theList.begin();
print_list_element(it);
return 0;
}
If you try to compile this with g ++ v4.3.2, it complains about the message that:
main.cpp:14: error: no matching function for call to 'print_list_element(std::_List_iterator<int>&)'
Is there something wrong with the code I wrote, or that g ++ needs more information?
source
share