What is wrong with this:
I want to be able to create a template function using the list container, so i can print lists of ints, doubles, strings, etc....Code:
template<class T>
void printList(const List<T> &list)
{
...
}
thanks
Printable View
What is wrong with this:
I want to be able to create a template function using the list container, so i can print lists of ints, doubles, strings, etc....Code:
template<class T>
void printList(const List<T> &list)
{
...
}
thanks
Works good for me
Code:#include <iostream>
#include <list>
using namespace std;
template<class T>
void PrintList( const list<T>& l )
{
list<T>::const_iterator walker = l.begin();
while( walker != l.end() )
{
cout << *walker++ << endl;
}
}
int main()
{
list<int> l1;
l1.push_front(1);
l1.push_front(2);
l1.push_front(3);
l1.push_front(4);
PrintList(l1);
list<char *> l2;
l2.push_front("one");
l2.push_front("two");
l2.push_front("three");
l2.push_front("four");
PrintList(l2);
list<char> l3;
l3.push_front('a');
l3.push_front('b');
l3.push_front('c');
l3.push_front('d');
PrintList(l3);
}
thanks
The reason your original one didn't work is this.
You had this declaration:
What is List? This should be changed to list, then your actual variable should be something other than the type name.Code:void printList(const List<T> &list)
Code:void printList(const list<T> &myList)