Travelsonic, on 13 October 2016 - 11:03 PM, said:
So... NodeType is a pointer to a NodeType.... and List is typedefed as a NodePtr, so... I can treat the List object as a pointer to a NodeType?
NodePtr is of type NodeType*, and List is the same as NodePtr. I still get confused by typedefs sometimes, which is why I now prefer
using.
SupperTails66, on 14 October 2016 - 03:27 AM, said:
if there's some further technical distinction, someone better versed in the language than I am can tell you, but it's probably not relevant to your needs anyway.
Pretty much. They'll both perform this job functionally the same as far as usage goes. Once compiled though, a class will have a
vtable, whereas a struct typically won't. But that doesn't really matter here.
Travelsonic, on 14 October 2016 - 07:00 AM, said:
Now, here's another problem: I noticed that the functions taking in a pointer to a List are taking in a pointer. This shows how long it has been since last doing C++, but wouldn't I still be passing by value, creating a copy of,it, rather than modifying the original? Wouldn't I need to add the address-of operator so it is actually being passed by reference? IF so, I am gonna hit a brick wall quickly, as my prof. seems to not want ANY changes to the declarations for the functions we are going to be implementing. Then again, part of me feels like I am missing something, a trick so to speak that would let me get away with not explicitly using the address-of operator, or I am just a grade-a dumbass. >_<
So you're confused by the functions that take List*? The functions that take in List* (where List is NodeType*, meaning List* is NodeType**) do so in order to change where your NodeType* is pointing. So if you have a List variable, you would in fact need to pass it in using &. This will give the function a pointer to your pointer. POINTERS EVERYWHERE!
In case my explanation wasn't clear, I'll use clearList as an example. Here's what our (fake) definition of clearList looks like.
Quote
void clearList(List* list)
{
// Clear all the data that needs to be cleared...
...
// Now we can change the value of list to null by dereferencing it. (nullptr == 0)
*list = nullptr;
}
This is effectively the same as taking in a pointer to say, an int, and changing its value by *value = 1234. The only difference is that our value is yet another pointer.
Now let's put it to use:
Quote
// (nullptr == 0)
List myList = nullptr;
// Initialize our list
initializeList(&myList);
// Our pointer, myList, is now a valid pointer, so we can add some data.
...
// Now our list has data in it, but we're done using it and want to clear it.
// We pass in a pointer to our list (pointer to a NodeType pointer) so that clearList can change the
// value of our pointer to nullptr, as all of its data has been freed.
clearList(&myList);
// myList is now null, pointing nowhere. Any further attempts to access it will cause a runtime exception.