I'm currently completely an assignment for my software engineering course at university and I've run into a brick wall when trying to put everything together.
The assignment consists of a Linked List class, Node class and a Train class. I've finished implementing the Node / Linked List classes but when trying to compile a TrainDemo I keep getting this linking error:
/tmp/ccmZn5Ek.o:Train.cpp:<.text+0x2e>: undefined reference to 'linked_list_class::linkedlist::list_locate<node_c lass_trent::node*, unsigned int>'
Here's the .h for my Train class:
Code:
#ifndef TRAIN_MACRO_GUARD#define TRAIN_MACRO_GUARD
#include "linkedlist.h"
using namespace linked_list_class;
namespace train_class
{
class Train
{
public:
typedef node::value_type value_type;
// Constructors;
Train();
Train(int arr[]);
// Destructors;
~Train();
// Mutating member functions;
void addLoad(int i, int j); // i = Kilograms of coal, j = Carridge;
void removeLoad(int i, int j); // i = Kilograms of coal, j = Carridge;
void removeCar(int i);
void cleanTrain();
// Non-mutating member functions;
int totalLoad();
int size();
private:
linkedlist* list;
};
}
#endif
Here's what I've written for the .cpp of the Train class so far:
Code:
#include "Train.h"
namespace train_class
{
// Constructors;
Train::Train()
{
list = new linkedlist();
}
Train::Train(int arr[])
{
list = new linkedlist();
for(int i = 0; i != -1; i++) // Minus -1 workaround to find the end of the array due to sizeof() issues;
{
list->list_head_insert(list->get_head(),i);
}
}
// Mutating member functions;
void Train::addLoad(int i, int j)
{
node* new_node;
new_node = list->list_locate(list->get_head(),j++); // list_locate returns a pointer to the previous node instead of the one we're looking for;
new_node->set_data(i); // This isn't a bad thing as some functions ( such as list_insert ) need the previous pointer;
} // As a workaround to avoid implementing a variation of the list_locate function to return
} // the actual node we're looking for, we can just add +1 to j;
And here's the .cpp I was using to test the Train class:
Code:
#include "Train.h"
using namespace std;
using namespace train_class;
int main(void)
{
Train* new_train = new Train();
}
Any help would be fantastic.
Thank you.