I am writing a linked list implementation as part of a larger program I am designing, but there is an error I can't seem to figure out:
Code:
./src/list.cpp:89: undefined reference to `show::show(std::string, std::string, std::string, bool, show*)
The error looks straghtforward enough, but I cant see what is wrong with the signature in question.
Here is the code:
list.cpp:
Code:
#include "list.h"
#include "show.h"
using namespace std;
list::list() {
// TODO Auto-generated constructor stub
m_head = new show();
}
show::show()
{
episodeTitle = "none";
seriesTitle = "none";
recordDate = "000";
isTivoSuggested = false;
nextShow = NULL;
}
bool list::ListIsEmpty()
{
return m_head ->nextShow == NULL;
}
list::list (const list& otherList)
{
CopyData (otherList);
}
list& list::operator=(const list l2)
{
if( this != &l2) // check for self-assignment
{
//1- cleanup current list
DeleteItems(this ->m_head);
//2 copy over new data
CopyData(l2);
}
//3
return *this;
}
bool list::addItem (string showTitle, string seriesTitle, string showRecordDate, bool isSuggested)
{
show *CurrentNode = m_head ->nextShow;
show *PreviousNode = m_head;
if (ListIsEmpty())
{
CurrentNode = new show (showTitle, seriesTitle, showRecordDate, isSuggested, NULL); //error is on this line
m_head ->nextShow = CurrentNode;
//CurrentNode ->info = item;
return true;
}
else
{
if (showTitle == CurrentNode ->episodeTitle)
{
return false;
}
while (CurrentNode ->episodeTitle < showTitle)//doesn't work
/* the second condition in the above while statement is what to do if we reach the end of the list*/
{
if (CurrentNode -> nextShow == NULL/* if we have reached the end of the list*/)
{
CurrentNode ->nextShow = new show (showTitle, seriesTitle, showRecordDate, isSuggested, NULL); //here too
// PreviousNode -> NextNode = CurrentNode;
//CurrentNode = CurrentNode ->NextNode;
//CurrentNode ->info = item;
return true;
}
CurrentNode = CurrentNode ->nextShow;
PreviousNode = PreviousNode ->nextShow;
/*Set position between nodes*/
}
//if we not at the end of fhe list, the following code will re-adjust the pointers
PreviousNode ->nextShow = new show(showTitle, seriesTitle, showRecordDate, isSuggested, NULL);
PreviousNode = PreviousNode ->nextShow;
PreviousNode ->nextShow = CurrentNode;
}
return true;
}
void list::ShowList() //this part will need to be expanded for more dynamic options
{
show *currentShow = m_head ->nextShow;
while (currentShow != NULL)
{
cout << currentShow ->episodeTitle << endl;
cout << currentShow ->seriesTitle << endl;
cout << currentShow ->recordDate << endl << endl;
currentShow = currentShow ->nextShow;
}
}
bool list::FindItem(string showTitle)
{
show *currentShow = m_head ->nextShow;
while (currentShow != NULL)
{
if (currentShow ->episodeTitle == showTitle)
{
return true;
}
if (currentShow ->episodeTitle > showTitle)
{
//this works since shows are alphabetized
return false;
}
currentShow = currentShow ->nextShow;
}
return false;
}
bool list::DeleteItem(string showTitle)
{
show *previousShow = m_head;
show *currentShow = m_head ->nextShow;
if (FindItem (showTitle))
{
while (currentShow != NULL)
{
if (currentShow ->episodeTitle == showTitle)
{
previousShow ->nextShow = currentShow ->nextShow;
delete currentShow;
return true;
}
else
{
currentShow = currentShow ->nextShow;
previousShow = previousShow ->nextShow;
}
}
}
return false;
}
void list::DeleteItems(show *currentShow)
{
/*CurrentNode starts off as m_head*/
if (currentShow ->nextShow != NULL) //base case
{
DeleteItems (currentShow ->nextShow);
/*Each node must delete itself, but only the base case has a null at the end,
therefore, deletion and return statements must go outside the loop*/
}
delete currentShow;
return;
}
void list::CopyData (const list& list2)
{
show *showcopy = list2.m_head ->nextShow;
show *thisShow = new show();
while (thisShow != NULL)
{
//copy one node into another
thisShow ->nextShow = new show(showcopy ->episodeTitle, showcopy ->seriesTitle, showcopy ->recordDate, showcopy ->isTivoSuggested, NULL);
//Advance both pointers
thisShow = thisShow ->nextShow;
showcopy = showcopy ->nextShow;
}
}
list::~list() {
// TODO Auto-generated destructor stub
DeleteItems (m_head);
}
list.h:
Code:
#include <iostream>
#include <string>
//#include "show.h"
using namespace std;
#ifndef LIST_H_
#define LIST_H_
class list {
public:
list();
list (const list &otherList);
bool addItem (string showTitle, string seriesTitle, string showRecordDate, bool isSuggested); //this is the signature
bool DeleteItem (string show);
bool FindItem (string show);
bool ListIsEmpty();
list& operator=(const list l2);
void ShowList ();
virtual ~list();
struct show *m_head;
private:
void DeleteItems (show *m_head);
void CopyData (const list& list2);
};
#endif /* LIST_H_ */
What am I doing wrong?
Thanks.
S