So I've been working on this program to maintain LinkedList, and I've gone to now use templates, for code reusability and such.
I'm getting the error undefined reference to LinkedList<float>::clear()
as well as all other functions.
im not sure how to approach this error, i would write a function for the float case but that defeats the purpose of templating. Anyways thanks for any help
#include <iostream>
#include "LinkedList.h"
usingnamespace std;
bool badOp(int);\
template<class type>
void selectCase(int, LinkedList<type>*);
template<class type>
void createList(LinkedList<type>*);
template<class type>
void addTo(LinkedList<type>*);
template<class type>
void removeFrom(LinkedList<type>*);
template<class type>
void clearList(LinkedList<type>*);
template<class type>
void changeName(LinkedList<type>*);
int main()
{
LinkedList<float> * theList=new LinkedList<float>();
int op=0;
cout<<"Welcome user, how can we help you?"<<endl;
while(op!=7){
cout<<"\n(1) Create a blank list.\n(2)Add to existing list\n(3)Remove from existing list.\n(4)Clear existing list\n(5)Change name associated with list\n(6) Print list\n (7) Exit Program\n\n";
cout<<"Please enter a number from 1-7\n";
cin>>op;
while(badOp(op)){
cout<<"\nInvalid Entry, please reenter your selection.\n";
cin>>op;
}
selectCase(op, theList);
}
}
template<class type>
void selectCase(int op, LinkedList<type>* theList){
switch(op){
case 1:
createList(theList);
break;
case 2:
addTo(theList);
break;
case 3:
removeFrom(theList);
break;
case 4:
clearList(theList);
break;
case 5:
changeName(theList);
break;
case 6:
theList->print();
break;
case 7:
cout<<theList;
cin>>op;
break;
}
}
bool badOp(int op){
return (op>7 || op<1);
}
template<class type>
void createList(LinkedList<type>* l){
l->clear();
cout<<"\nWhat will you name the new list?\n";
std::string n;
cin>>n;
l->setName(n);
}
template<class type>
void addTo(LinkedList<type>* l){
int n;
cout<<"\nWhat grade would you like to add to the list?\n";
cin>>n;
if(n>=0)
l->add(n);
else
cout<<"\nThe grade must be a positive number.\n";
}
template<class type>
void removeFrom(LinkedList<type>* l){
if(!l->isEmpty()){
l->remove();
cout<<"\nThe last added file has been removed.\n";
}
else{
cout<<"This list is empty.";
}
}
template<class type>
void clearList(LinkedList<type>* l){
l->clear();
cout<<"\nThe list has been cleared.\n";
}
template<class type>
void changeName(LinkedList<type>* l){
std::string name;
cout<<"\nWhat would you like to rename your list?\n";
cin>>name;
l->setName(name);
}