I am some what new to c++, I am making a linked list and am a bit confused at how it works. I have looked at several examples online and they all use strutcs where everything is public and I need to do it using a class where they are private. I am not sure how to access the private members Word * next and Word * previous. I have the member function for set and get of adding the English and Finnish words. I just need help in how to set and get the next and previous values.
so I have a class as follows:
class Word{
public:
/*Constructor*/
Word();
/*Destructor*/
~Word();
void SetNext(Word *num) {next = num;}
Word GetNext() {return *next;}
private:
char *pEnglish;
char *pFinnish;
Word *next;
Word *previous;
};
and my main is like this
int main()
{
Word *node;
node->SetNext(0);
if (node->GetNext() !=0)
{
//do something
}
return 0;
}
It give the error:
error: no match for 'operator!=' in 'Word::GetNext()() != 0'
I have looked this error up and really don't get any help for it. My guess is that I may need to overload the operator or something but I am lost.
So how to I check its value so I can start to create the link list?
I am lost when it's private. I put it public and I can make it work just fine.
Any help or hints would be great.
Thanks for the help in advance.
The list, the node and the data should be different things.
The list need access to the links in the node. You could then make the node an inner class, with its members public, or make the list a friend of the node.
As a user, you care about the data. You want to be able to insert and retrieve data. You don't care about nodes or links.