parser.cpp: In function ‘void dump_to_stdout(TiXmlNode*, unsignedint)’:
parser.cpp:28: error: ‘interpreter’ was not declared in this scope
parser.cpp:44: error: ‘interpreter’ was not declared in this scope
I am not sure why interpreter would not be declared. In the main function I initialized an instance of the ParseInterpreter class and called it interpreter. The functions being called are public functions so any other function should be able to call them. Any suggestions?
Your error is telling you that interpreter isn't declared as you know.
One of the problems with defining a global variable in a header is that it isn't shared properly between source objects and if you don't have protections in your headers, it will likely be defined twice.
Define interpreter in your source file to ensure that it is created properly.
If you want to share the same object in multiple source files, then define it in one source file AND in the header with the extern keyword in front of the declaration.
It is clear that I am not using the object correctly. I do not understand why defining the class in the headerfile, linking to it and then defining an instance of the class in the source file does not place that object within the scope of the source file.
I am not sure where you suggest that I place the extern keyword.
Vlad, I admit that I am not sure exactly what it is that you are asking of me. If I have not shown the object definition, I am not sure what I would need to provide in order to do so.
I thought what I had written in the header file was the definition of the class and therefore any instance of the class. I seem to be wrong about this.
At some point in your code (likely at the top of one of your source files), you'll have to define interpreter as a ParseInterpreter.
I just noticed that it is defined in your main() at line 63. That object is created in your main, but no other functions can see it.
To make the other functions see it you can do one of the following:
1) Move line 63, to line 12 - AKA global scope (easier)
2) Add a ParseInterpreter object as an argument to dump_to_stdout() (better coding).
I made the declaration global just to see if the code would work. I was able to compile and run the code but now after trying to make some improvements I am running into another problem. It is related but different enough that I will post it in a new thread.