On 21.09.19 10:34, Ron Tarrant wrote:
Here's a question for the room:

Does a doubly-linked list always have to be done with structs? Can it be classes instead? (Maybe that's why I can't get it to work, because I've been trying to make an OOP version?)

It can be done with classes.

When I run the following code, it gets through creating the list head and the first node, then seems to get stuck in an infinite loop. Here's the code:
[...]
class Tab
{
[...]
     Tab* _prev = null, _next = null;
[...]
     Tab* getNext()
[...]
     Tab* getPrev()
[...]
     void setNext(Tab* tab)
[...]
     void setPrev(Tab* tab)
[...]
} // class Tab

Your mistake is that you're using pointers. `Tab` is a class. That means values of the type are already references. There is no need for `Tab*`. Just use `Tab` wherever you have `Tab*` now, and get rid of any addr-ofs (`&foo`) and dereferendces (`*bar`) you have.

Reply via email to