I\'m getting a incomplete type error for the \'next\' and \'previous\' variables. I\'m not sure what I am doing wrong because I am very rusty on writing classes in C++. An
it would appear that your trying to impliment a "linked list"
The structure of a linked is that next & previous "points" (*) and is not actually another node as Andre states.
http://www.cplusplus.com/doc/tutorial/pointers/ may help clarify.
class LinearNode
{
//...snip
//returns the next node in the set.
LinearNode* getNext();
//returns the previous node in the set
LinearNode* getPrevious();
//...snip
private:
LinearNode * next;
LinearNode * previous;
};
So in the implementation file:
//returns the next element in the structure
LinearNode* LinearNode::getNext()
{
return next; // now a poiner
}//ends getNext function
//returns previous element in structure
LinearNode* LinearNode::getPrevious()
{
return previous; // now a poiner
}//ends getPrevious function
//sets the next variable for the node
void LinearNode::setNext(LinearNode* node) //pointer in, void out
{
next = node
}//ends the setNext function
//sets previous for the node
void LinearNode::setPrevious(LinearNode* node)//pointer in, void out
{
previous = node;
}//ends the setPrevious function
so main looks like:
int main()
{
LinearNode node1, node2, move;
node1.setElement(1);
node2.setElement(2);
node2.setNext(&node1); // give the address of node to the next pointer (&)
node1.setPrevious(&node2); // give the address of node to the next pointer (&)
move = node2;
while(move.getNext() != NULL)
cout << move.getElement() << endl;
}
I don't know what the while loop's trying to do though! if - perhaps?
Also as Nicklamort states all your class functions need to have a return type, except in the case of void.