Q: How do I detect a mouse click? I don't think we learned about the mouse or graphics in class.
A: You don't have to handle mouse clicks directly. The provided GUI code does that. It waits for a mouse click, and when one occurs, it calls the appropriate member function on your code, such as raise or lower or remove.
Q: How do I declare a TileNode?
A: Since the tile stack needs to keep its memory around dynamically, you must use the 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
...
Q: My program crashes and the console says "The program has unexpectedly finished" in red text. Why is this? How do I find and fix it?
A: That error means that you have accessed illegal memory, such as a null pointer or garbage pointer. Try running your program in Qt Creator's Debug mode (the "Play" button with a bug on it, below the normal Play button) and then when there is a crash, you can view the call stack of which functions were running. Find the line number where your program crashed and look at that line to find your bug.
Q: When I click on a rectangle, the window briefly "flickers" before it updates. Is this my fault? Is my code too slow?
A: This is just a side effect of how the Stanford graphical libraries are implemented. It isn't your fault, and you don't need to worry about it.
Q: Can I declare a Vector as a private field inside my TileList?
A: No. The point of this homework is to practice implementing data structures from scratch, not to use an existing class or library.
Q: Should my class store a pointer to a TileNode? A pointer to a pointer? A reference to a pointer? How do I declare it? ...
A: Store a TileNode* , that is, a pointer to a TileNode.
Q: Are these the correct private member variables for my class? ______ Do I have too many/few?
A: Member variables represent the state of the object and should exist as is necessary to store that state. Temporary variables, elements of data that do not need to be remembered between member function calls or uses of the object, should not be fields.
Q: Do I need to write a destructor? If so, what should it do? When am I supposed to call the destructor?
A: Yes, you need to write a destructor. It should free any dynamically allocated memory used by your list (any memory that was initialized with the 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.
Q: Exactly what memory do I need to free (delete)? Do I need to free every int and pointer I declare? Do I need to free the TileList object itself? ...
A: You only need to free the object(s) that your code creates using 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.
Q: What is const? When do I need to make something const?
A: Make a member function 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.
Q: Why do my 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?
A: Testing for 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.
Q: What is the difference between a destructor and the clear method? Don't they do the same thing, deleting all elements from the tile stack?
A: A 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.
Q: Can/should I use a circular list instead of a nullptr-terminated list?
A: No, you shouldn't do this.
Q: I'm trying to debug by printing my nodes. But every time I try to print a node, it just prints a memory address in hex format. Why?
A: Maybe you're actually printing a 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.
Q: I've heard of something called a "smart pointer" that frees itself and doesn't require memory management and new/delete. Can I use that on this assignment?
A: Sorry, no. We want you to practice manually allocating and freeing memory on this assignment. Those kinds of libraries are useful, but we want you to build certain skills before becoming dependent on any particular library to help you.