我編譯記錄程序,但我收到此錯誤,並不能弄明白我的生活......C++類重定義錯誤
logger.cpp:15: error: redefinition of ‘class Logger’
logger.h:20: error: previous definition of ‘class Logger’
與當我編譯
g++ -Wall logger.cpp -o log
GCC
logger.h:
#ifndef LOGGER_H
#define LOGGER_H
#include <fstream>
#include <iostream>
#include <string>
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
logger.cpp
#include "logger.h"
#include <fstream>
#include <iostream>
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 << message << "\n";
std::cout << "you just wrote " << message << " to the log file!\n" << 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;
好的我做了更改,但現在我收到Logger()和〜Logger()的錯誤.............. logger.cpp:17:error:隱式聲明的定義'Logger :: Logger()' logger.cpp:17:error:'Logger :: Logger()'的聲明引發了不同的異常 logger.h:18:error:來自前一個聲明'Logger :: Logger()throw ()' – user603756 2011-02-04 21:46:39