I cannot figure out how I would call a template function that is suppose to take a string and College object as the parameters in my main.cpp.
This is my template in LinkedListADT.h:
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include "ListNodeADT.h"
template <class T>
class LinkedList
{
private:
ListNode<T> *head;
int length;
public:
LinkedList(); // constructor
~LinkedList(); // destructor
// Linked list operations
void insertNode(const T &);
bool deleteNode(const T &);
bool searchList(const T &, T &) const;
};
This is what I wrote so far for the search function in my LinkedListADT.h file:
template <class T, class S>
bool LinkedList<T, S>::searchList(const S &target, T &dataOut) const
{
bool found = false; // assume target not found
ListNode<T> *pCur;
while (pCur && pCur->getData().getCode() != target){
/*Code to search*/
return found;
}
This is the search function in my main.cpp that calls searchList from the header file which takes a user inputted college code. It is suppose to call searchList using the string input and try to find a match with a college code in the linked list:
void searchManager(const LinkedList<College> &list)
{
string targetCode = "";
College aCollege;
cout << "\n Search\n";
cout << "=======\n";
while(toupper(targetCode[0]) != 'Q')
{
cout << "\nEnter a college code (or Q to stop searching) : \n";
cin >> targetCode;
if(toupper(targetCode[0]) != 'Q')
{
if(list.searchList(targetCode, aCollege))
/*Code to display college*/
else
cout << "Not Found";
}
}
cout << "___________________END SEARCH SECTION _____\n";
}
I am sure this is not the way to write my template function in the header file because this would also change the template for the other template functions (insert, delete, etc). I would appreciate any suggestions on a way to correctly write it. Thanks everyone!