Two things. One, if a function in a class doesn't utilize any class member data, you can declare it static and access it via classname::function(), not needing to create an instance of the object. Doesn't look like it applies here, since your help object is populated with data for menuHelp to output, but something to keep in mind.
Two, and I can't stress this more strongly, learn the STL. I see you using node pointers and the like. Implementing your own linked lists is a sure way to get yourself into trouble. You could implement everything you did there much more simply with the STL.
Code:
#include <iostream>
#include <fstream>
#include <list>
class help {
public:
help();
~help();
void menuHelp();
private:
struct helpItem {
char helpOne[21];
char helpTwo[21];
char helpThree[21];
char helpFour[21];
char helpFive[21];
char helpSix[21];
};
std::list<helpItem> helpItems;
char filename[21];
};
Then in your constructor instead of following node pointers around to add/remove/read data, you just use STL list mechanics.
Code:
help::help() {
std::ifstream inputFile;
inputFile.open(filename, std::ios::in);
while( /* still reading data; I assume this is in a file but however */ ) {
helpItem newItem;
// load data into newItem.helpOne through newItem.helpSix
helpItems.push_back(newItem);
}
}
std::list's have the advantage of being bidirectionally linked and you have the ability to use a lot of built-in capabilities found in <algorithm> on them, like sorting, searching, etc. You also don't have to worry about garbage collection, bad pointers, memory leaks, etc. You'd access the data via an iterator, which uses syntax a lot like a pointer but knows how to travel through the linked list properly, like so:
Code:
void help::menuHelp() {
for (std::list<helpItem> helpIter = helpItems.begin(); // Gets an iterator to the start of the linked list
helpIter != helpItems.end(); // Checks to see if we've driven off the end of the list
++helpIter) { // Moves to the next entry in the linked list
cout << helpIter->helpOne << helpIter->helpTwo; // etc.
/* Note how helpIter is using pointer semantics to access its members. item->subitem is the same as (*item).subitem */
}
}
I'd recommend using std::string's instead of C-strings (char arrays) too, but didn't want to confuse the example by introducing two concepts at once. Obviously not knowing exactly what you're doing, my examples are going to be very generic, but it saves a lot of work storing and traveling along messy pointers. You can find a lot of great tutorials on using the C++ STL online.