// Use the Standard Libaray for-each instead of your own version of it. #include #include #include #include void print_element(int i){ std::cout << i << std::endl; } int main(){ std::list lst; lst.push_back(7); lst.push_back(9); lst.push_back(8); lst.push_back(1); lst.push_back(-1); // The two first parameters are iterators: std::for_each(lst.begin(), lst.end(), print_element); // 7 9 8 1 -1 }