I have written some code that contains a system to report error messages to error log file. I use a class structure to do this. However, some parts of the code contain functions that I think might be useful in a more generic context. So, I am trying to use preprocessor directives to redefine the class structure for those more generic instances when I will not want to use and error log file. Here is what I have come up with. . .
#ifdef USES_ERROR_HANDLER_H
#include "ErrorHandler.h"
#else
class InternalErrorReport
{
private:
string logfilename;
public:
void ProgramExit() const
{
cout << "\nAbnormal Program Exit.\n\n";
exit(9);
};
void report (const std::string& line) const
{
cout << line;
};
void report (const double& v) const
{
cout << v;
};
};
InternalErrorReport Log;
#endif
I use #define USES_ERROR_HANDLER_H in the main program code, and the header file Error_Handler.h contains the original error class and error reporting functions. Everything works fine if I use #include "Error_Handler.h" in the code.
Right now I am trying to get this to complie with USES_ERROR_HANDLER.H defined. So, everything should work like it worked before. However, when I use the code listed above I get a compiler error .. for code later on in the program that normally works fine. Since the code above is the only new code, the error has to be there. But where?
Any insights will be appreciated.