我有以下类,Base 和 Derived,当我编译编译器时抱怨它无法创建 DLog 的实例,因为它是抽象的。
有人能告诉我如何解决这个错误吗?
我猜这是因为并非两个纯虚函数都没有在派生中实现。
class Logger
{
public:
virtual void log(int debugLevel, char* fmt, ...) = 0;
virtual void log(string logText, int debugLevel, string threadName = "") = 0;
static Logger* defaultLogger() {return m_defaultLogger;}
static void setDefaultLogger(Logger& logger) {m_defaultLogger = &logger;}
protected:
static Logger* m_defaultLogger;
};
class DLog : public Logger
{
public:
DLog();
~DLog();
static DLog *Instance();
static void Destroy();
void SetLogFilename(std::string filename);
void SetOutputDebug(bool enable);
std::string getKeyTypeName(long lKeyType);
std::string getScopeTypeName(long lScopeType);
std::string getMethodName(long lMethod);
virtual void log(string logText, int debugLevel)
{
Log(const_cast<char*>(logText.c_str()));
}
void Log(char* fmt, ...);
private:
static DLog *m_instance;
std::string m_filename;
bool m_bOutputDebug;
};
// DLog 实例化为单例
DLog *DLog::Instance()
{
if (!m_instance)
m_instance = new DLog();
return m_instance;
}