I just can’t win with headers it seems.
I have a class Log of which has a header Log.h that defines the class Log, and then the Log.cpp implements the methods of Log. I need it available in Main.cpp, so I include Log.h into Main.cpp and I receive the notorious “already defined” errors.
If I take out the header from Main.cpp, I can’t use the class.
If I take out the header from Log.cpp, then Log is (obviously) not defined.
I can’t win here! What do I do?
EDIT YES, of course I have include guards.
#ifndef LOG_H_
#define LOG_H_
namespace vexal {
#define CCOL_RESET "^[[0m"
#define CCOL_RED "^[[31m"
class Log {
public:
Log();
virtual ~Log();
static void genInstance();
private:
static Log* _inst;
};
}
#endif /* LOG_H_ */
Then the includes are merely #include "Log.h" in both Log.cpp and Main.cpp.
The issue ended up being the order of which the includes were included. Some includes have to be included before others to avoid redefinition issues.