I’m trying to cycle through the data contained in each node in a list called _snakeSegments. (note: classes have been written by myself and are not part of STL ect). Each data element is a Sprite that represents a single segment of my snake.
I’m getting the following error when i try to compile: request for member 'GetPrev' in 'currentNode', which is of non-class type 'Node<Sprite>*'. The compiled has flagged the line where i try to assign the next currentNode in the for loop below:
void Snake::Draw(prg::Canvas& c)
{
Node<Sprite>* currentNode = _snakeSegments.GetHead();
for (int i=0; i < _snakeSegments.NumberOfNodes(); ++i){
currentNode->GetData().Draw(c);
currentNode = currentNode.GetPrev(); //compiler shows error here
}
}
Heres the definition of GetPrev. Which, when called upon a node, returns a node pointer to the previous node..
template <typename NodeType>
Node<NodeType>* Node<NodeType>::GetPrev()
{
return _prev;
}
Um well i’m a little confused and would appreciate any help! Please ask if you need more information/ i’m being unclear, thanks.
currentNodeis a pointer, which means you need to access its attributes via `->, like you did on the line above:You should really try to learn to differentiate between pointers and instances. Pointer attributes are always referred to via
->.