I'll try and make this somewhat short. I had an assignment to make a c++ inheritance program that uses 5 headers and 5 cpp's with a main. One header/cpp inherits the other 4 and main calls the base..basic. So I had trouble understanding inheritance and it took me a bit, but got it going. Now the assignment is to revise the program using linked list to load the user input for the address book program. - My text book for school sucks, the professor even hates it. I got another c++ book to help and the two contradict one another. The question I have, is which is better, class or struct? I have all the classes built, or can you just use a struct inside the class? (we skipped templates due to time left in semester, so haven' grasp/dove into that yet). I will show one of the smallest classes. It is used to set name when when inherited base class is called from main() to user into set name.( now how to set it up in linked list input)
Or would struct be used sort of like a prototype in the since it goes before the header as such
1 2 3 4 5 6 7 8 9 10 11 12
struct Node{
string firstName, lastName;
node *link
*head
};//end struct
class personType{
public:
personType();
private:
//whatever here
}; //end personType class
Am I sort of on the right track? Just looking for a push in the right direction please...tired and confused a bit. Thanks to all, regards.
(singly linked list btw)
The only differences between class and struct are:
1) Default inheritance for class is private, for struct is public;
2) Default access for class is private, for struct is public;
3) struct is 6 keystrokes, class is 5.
One nests classes/structs when there is a logical relationship between them. Almost always when I do this it is because the nested type should be private within the class (ie, the user doesn't need to use it directly). If you are building a linked list class and you need a node class/struct, unless the user must directly use the node class (which they shouldn't), node should be declared in the protected or private section of the linked list class.