Originally, my class was written as a stand-alone, standard string linked list class using pointers. Within the 'linkedlist' class, you will find a struct 'item' privately encapsulating two variables. One variable in the private 'item' class is named 'value' and is assigned the string data type from the std library. I chose string instead of fussing with a native data type like char[] that has less jazz and more code. The second data type is a pointer to the next 'item'; hence the name 'next'. I discovered a new method of declaring a variable immediately following the 'item' struct declaration which I learned is referred to as "direct declare". Essentially, a pointer to the first 'item' created can be declared immediately (give or take your preferred spacing) after the 'item' struct's right bracket. No type is required to declare this variable. If need be, you can declare multiple "direct declare" variables here. If you require more than one "direct declare" variable, the first is followed by a comma and then the second by pointer and name only (again, no type is required). I haven't discovered a limit to the "direct declare" variables you can have nor have I read of any; however, I haven't had a need for more than one. This variable is the most important variable in my implementation of a singly linked list.
The 'linkedlist' class is split between two files, one implementation file and one header file. Within the header file (linkedlist.h), I explain each constructor, assignment operator, destructor, copy constructor, mutator member function and accessor member function in greater detail and have the code wrapped in macros to prevent duplicate definitions. The implementation file (linkedlist.cpp) contains the logic of the above detailed items in the header file (linkedlist.h) and performs all necessary computations, algorithms, data manipulations, etc. For additional readability and easier debugging, each block of code is limited to 5-10 lines; although, I may have exceeded this on one or two by only a cpl lines. Where I believe I can improve on this is marked by the verbiage "to do: improve" and may have "notes:" comments.
Many of the functions were created for a previous assignment and will either be permanently removed or left commented out in assignment 2. Those that are not removed and left for hopeful usage in the next version of 'linkedlist' will at least be converted to using the Template method and tested prior to be commented out. At this point, I am struggling with converting a once functional, error-free and tested 'linkedlist' object with a Template. Also, I managed to compile the files in a Windows g++ and on Kutztown University's g++ *successfully* prior to mangling the code with Template guesses. Earlier tonight, I was fighting with preprocessor directive '#include "linkedlist.cpp"' in the very end of 'linkedlist.h' file without getting compiling errors. Oddly, when I placed '#include "linkedlist.h"' in the beginning of the 'linkedlist.cpp' file only, all was well. At first, I assumed it was a bug in my compiler being on a Windows machine; however, the same result occurred on Kutztown University's machines. Using Command, I ftp’d main.cpp, linkedlist.h and linkedlist.cpp to my student directory (all in one directory). Afterwards, I compiled the files linkedlist.cpp and main.cpp using g++ to create a.out. I did this twice - once for each way the preprocessor directives were placed in the files explained above, each result was identical to its compilation on Windows. I still to this moment do not understand why that happened or how it was resolved; however, if it occurs again, I will not hesitate to write '#include "linkedlist.h"' in the beginning of 'linkedlist.cpp' ... I like it there better anyway and my IDE will stop bitching at me.
I have commented out the majority of the code to only work on one block at a sitting and test rigorously. Sadly, I have nearly every member commented out at this time and am beginning to not like this Template idea too much. Maybe I was influenced by learning one of the primary programmers involved in the C++ Standard Template Library is anti-OOP. Huh? Seriously? Really? Template coding is horrific and less understandable for me right now - maybe that will change once I understand it more.
No comments:
Post a Comment