I'm having a problem with defining a namespace and I know I'm going to shoot myself once I get it figured out.
Anyway, I have the following header file with namespace defined:
Code:
#ifndef __LOGGER___
#define __LOGGER___
#include <string>
#include <fstream>
using namespace std;
namespace LogFile
{
std::ofstream logFile;
void openLogFile(const char *filePath)
{
logFile.open("log.log");
}
void closeLogFile()
{
logFile.close();
}
}
#endif
Fine and dandy.
When I include the header file in more than one CPP file, I get linker errors (e.g., symbol has already been defined in ***.cpp).
Clearly I'm not doing something right. I did a search on Google but I'm not finding anything relevant (most of the results revolve around the std namespace).
I would appreciate any hints as to why I'm getting these linker errors. For an exact quote from the linker: "error LNK2005: "void __cdecl LogFile:penLogFile(const char*)" (?openLogFile@LogFile@@YAXPBD@Z) already defined in main.obj"