Hello,
I am getting an error when I try to pass a linked list and an iterator to the printList function below. For some reason it does not recognize the printList function call.
I get the following error on line 39.
no matching function for call to 'printList(std::_List_iterator<Event, std::allocator<Event> >&'
#include "utility.h"
#include "Item.h"
#include "Event.h"
using namespace std;
template< typename T > void printStack( T &stackRef );
template< typename T > void printQueue( T &queueRef );
template< typename T > void printList( T &it, T &list );
int main()
{
Event planeChicago;
Event planeDallas;
planeChicago.makeEvent(6, "plane", "Chicago");
planeDallas.makeEvent(5, "plane", "Dallas");
// List Testing ====================================================================================================
list<Event> mylist;
list<Event>::iterator current; //pointer into the list
mylist.push_back(planeChicago); //insert value at front of list
mylist.push_back(planeDallas); //insert value at back of list
cout << "the list contains: " << endl;
for (current = mylist.begin(); current != mylist.end(); current++)
{
cout << *current;
}
mylist.sort();
printList(current, mylist); // error: no matching function for call to 'printList(std::_List_iterator<Event, std::allocator<Event> >&'
// cout << "the list contains: " << endl;
// for (current = mylist.begin(); current != mylist.end(); current++)
// {
// cout << *current;
// }
// End List Testing ====================================================================================================
template< typename T > void printStack( T &stackRef )
{
for (int j = 0; j < 12; j++)
{
cout << j << ") " << stackRef.top(); // Returns top element of stack
stackRef.pop(); // Removes top element from the stack
}
}
template< typename T > void printQueue( T &queueRef )
{
for (int j = 0; j < 12; j++)
{
cout << j << ") " << queueRef.front(); // Returns top element of stack
queueRef.pop();
}
}
template< typename T > void printList( T &it, T &list )
{
cout << "the list contains: " << endl;
for (it = list.begin(); it != list.end(); it++)
{
cout << *it;
}
}