I am currently self-studying header files, implementation files and the like. The program that I'm trying to write takes a singly linked list of integers and reverses the order of them. From everything that I have read, I should have a header and source file for each class, struct etc. The problem that I have is getting the files to "see" each other, as in, #include... The error I am getting is "Node is undefined". The IDE I am using is Microsoft Visual C++ 2010 Express. If anyone can point me in the right direction with this, I would be greatly appreciative. The files I have thus far are below. Once I can get this code to compile I will be adding a stack class and incorporating it into the code. Thank you in advance for any and all help.
namespace linkedlist
{
class LinkedList
{
private:
node::Node *head;
Also consider revising the use of namespaces in your code. There is not much point in pacing each class in a separate namespace (which has the same name as the class with the case changed.)
Thank you JLBorges. I do agree that the use of the namespaces is overkill. I recently learned about them as I was trying to incorporate them into my code so that I could actually use them and it not be something that I just read about in one of my textbooks. If I may ask, if I remove the namespaces, is the code somewhat "close" as to how a professional software developer would go about making a simple program like this? Thanks again!
> if I remove the namespaces, is the code somewhat "close" as to how
> a professional software developer would go about making a simple program like this?
As far as names and namespaces go, a professional software developer might do something like this:
1 2 3 4 5 6 7 8 9 10 11 12
namespace utility // or whatever
{
class linked_list
{
private:
class node // node is an implementation detail that does not appear
// in the interface of linked_list and is not directly accessible by users
{
// ...
};
};
}
There are may other things that a professional software developer might do. For self-study of header files, implementation files and the like, focus on the placement and visibility of names.
For that, this much should be adequate.
Caveat: assuming that 'professional software developer' understands C++ well (there are too many who don't).