Hi Guys,
First post on here :) I've been here before and i've usually been able to find what I needed but now I'm in a bit of a bind.
I'm doing a piece of coursework for my university course and i've just hit a huge brick wall. Basically what I have to do is use a Linked List to store strings (Each node stores 1 string). I need a function to add a node, and one to print the contents of the list to the console. The problem is that I have to do it using 3 files. One header and one cpp to declare all the functions etc. and a third test.cpp to write some tests.
I haven't even started the test conditions because all that I keep getting are 3 errors.
1 - 'initialise' was not declared in this scope
2 - 'addNode' was not declared in this scope
3 - 'printContents' was not declared in this scope
All these errors are in the main method. Just incase this may be relevant, I'm using Xcode. I usually use Visual Studio 2010 but I wont have access to it until tomorrow.
Heres the code I have so far for my Dictionary.h file:
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <iostream>
using namespace std;
class DictionaryTree
{
private:
struct node {
string x;
node *next;
};
node *root;
node *conductor;
DictionaryTree() { }
public:
void addNode (string word);
void initialise();
void printContents();
};
#endif
And here is my Dictionary.cpp:
#include <iostream>
#include "Dictionary.h"
void DictionaryTree::addNode (string word)
{
conductor->next = new node; // Creates a node at the end of the list
conductor = conductor->next; // Points to that node
conductor->next = 0; // Prevents it from going any further
conductor->x = word;
}
void DictionaryTree::initialise()
{
root = new node;
root->next = 0;
root->x = "";
}
void DictionaryTree::printContents()
{
conductor = root;
if ( conductor != 0 ) {
while ( conductor->next != 0 ) {
cout<< conductor->x;
cout << endl;
conductor = conductor->next;
}
cout<< conductor->x;
cout << endl;
}
}
int main()
{
initialise();
addNode("Test1");
addNode("Test2");
printContents();
}
Any help would be very appreciated. Im about to put my head through a wall on this one :)