raise or lower or remove.
TileNode?
new keyword like this:
TileNode* node = new TileNode(x, y, w, h); node->color = ...; node->prev = ...; node->next = ...; ...
You *must* declare all your nodes as pointers; do not declare them as regular objects like the following code, because it will break when the list node goes out of scope:
// do not do this! TileNode node; // bad bad bad node.x = 42; // bad bad bad no node.y = 17; // bad bad bad no stop node.next = nullptr; // bad bad bad no stop don't ...
Vector as a private field inside my TileList?
TileNode? A pointer to a pointer? A reference to a pointer? How do I declare it? ...
TileNode* , that is, a pointer to a TileNode.
new keyword).
You don't explicitly call the destructor; the client program automatically calls it when the TileList variable it creates falls out of scope.
delete)?
Do I need to free every int and pointer I declare?
Do I need to free the TileList object itself? ...
new.
You don't need to free an int; its memory is reclaimed automatically.
Any memory that was not allocated using new is already handled by the program without any code from you.
Just free your nodes by calling delete on each pointer to a node that is removed from the list.
const? When do I need to make something const?
const when it does not modify the state of the object it is called on.
Examples of such methods are accessors / "getters" like getX or isEmpty, as well as methods that just display information like toString, print, draw, etc. But a member function that modifies the object, like nextDay, setY, or clear would not be const.
Also use const in front of a parameter to a function, if that parameter is a reference to an object and your member function does not make any modifications to that parameter's state.
Like if the client passes you a reference to a string or Map and you examine but don't modify it, make the parameter const.
while loops always crash?
I explicitly check for null and tell my loop to stop when nullptr is reached.
Shouldn't the loop stop successfully?
nullptr is good, but it only works if you actually set the appropriate node pointer to nullptr.
Are you sure that you did that? (Such as in your constructor)
Remember that if you don't explicitly set an empty pointer to nullptr, it will point to garbage, and the program will likely crash if you try to follow the pointer.
clear method?
Don't they do the same thing, deleting all elements from the tile stack?
clear method is called explicitly when a client wants to wipe the elements and then start over and use the same stack to store something else.
A destructor is called implicitly by C++ when an object is being thrown away forever; it won't ever be used to store anything else after that.
The implementations might be similar, but their external purpose is different.
nullptr-terminated list?
TileNode*, that is, a pointer to a node.
Print the node itself (*p rather than p); just be careful that the pointer is not null or garbage before following it.
new/delete.
Can I use that on this assignment?