title: C++ class redefinition error
body: <p>I am compiling a logging program, but I am receiving this error and cant figure it out for the life of me...</p>
  
  <pre><code>logger.cpp:15: error: redefinition of ‘class Logger’
  logger.h:20: error: previous definition of ‘class Logger’
  </code></pre>
  
  <p>with gcc when i compile with </p>
  
  <pre><code>g++ -Wall logger.cpp -o log
  </code></pre>
  
  <p>logger.h:</p>
  
  <pre><code>#ifndef LOGGER_H
  #define LOGGER_H
  
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using std::string;
  
  class Logger
  {
  
  static Logger* m_pInstance;
  
  public:
  static Logger* Instance() { return m_pInstance; }
  void writeLog(string message);
  void openLogFile(string fileName);
  void closeLogFile();
  void deleteLogger();
  
  };
  #endif
  </code></pre>
  
  <p>logger.cpp</p>
  
  <pre><code>#include "logger.h"
  
  #include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  class Logger
  {
  static Logger* m_pInstance;
  std::ofstream m_pOutputFile;
  Logger()
  {
  }
  ~Logger()
  {
  }
  
  public:
  static Logger* Instance()
  {
      if(!m_pInstance)
      {
          m_pInstance = new Logger;
      }
      return m_pInstance;
  }
  void writeLog(std::string message)
  {
      m_pOutputFile &lt;&lt; message &lt;&lt; "\n";
      std::cout &lt;&lt; "you just wrote  " &lt;&lt; message &lt;&lt; "  to the log file!\n" &lt;&lt; std::endl;
  }
  void openLogFile(std::string fileName)
  {
      m_pOutputFile.open(fileName.c_str(),std::ios::out);
  }
  void closeLogFile()
  {
      m_pOutputFile.close();
  }
  void deleteLogger()
  {
      delete m_pInstance;
  }
  };
  Logger* Logger::m_pInstance = NULL;
  </code></pre>