-
Q: How do I compare strings to see which comes earlier in ABC order?
-
A: C++ string objects support the standard comparison operators like <, <=, >, >=, ==, and != .
-
Q: How can I implement
operator << for printing a priority queue?
It seems like the operator would need access to the private data inside of the priority queue object.
-
A: The
<< operator in our assignment is declared with a special keyword called friend that makes it so that this operator is able to directly access the private data inside the priority queue if needed.
-
Q: What am I supposed to do in a destructor?
-
A: Free up any dynamic memory that you previously allocated with the
new keyword.
-
Q: What is the difference between a destructor and the
clear method?
Don't they do the same thing, deleting all elements from the queue?
-
A: A
clear method is called explicitly when a client wants to wipe the elements and then start over and use the same list 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.