O
O
Oleg Pravdin2017-09-13 23:08:04
C++ / C#
Oleg Pravdin, 2017-09-13 23:08:04

How to interact with a pointer in a struct through a pointer?

There is a stack implementation based on a singly linked list:

struct ListElement {
  char element;
  ListElement* nextaddres;
};

class MyList {
  ListElement *head; //Верхушка стека
  bool Empty()
}

the stack has an Empty method that returns a bool depending on whether the stack is empty:
bool MyList::Empty() {
  return *head->nextaddres == nullptr ? true: false;
}

The latter, when compiled, produces a type mismatch in comparison (ListItem and std::nullptr). How to fix this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-09-13
@opravdin

Do not dereference the pointer. return *head->...Should be instead return head->....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question