我得到这个界面我已经写了:C++ - 虚拟析构函数和链接错误
#ifndef _I_LOG_H
#define _I_LOG_H
class ILog {
public:
ILog();
virtual ~ILog();
virtual void LogInfo(const char* msg, ...) = 0;
virtual void LogDebug(const char* msg, ...) = 0;
virtual void LogWarn(const char* msg, ...) = 0;
virtual void LogError(const char* msg, ...) = 0;
private:
Monkey* monkey;
};
#endif
的方法都是纯虚函数,因此必须通过派生类实现。 如果我尽量让继承这个界面我得到以下链接错误类:
Undefined reference to ILog::ILog
Undefined reference to ILog::~ILog
我明白为什么有一个虚拟的析构函数(以确保派生的析构函数被调用),但我不明白为什么我得到这个链接器错误。
编辑:好的,所以我需要定义虚析构以及。 但是我仍然可以在虚拟析构函数的定义中执行东西,还是只是简单地调用我的派生类析构函数并跳过它? 一样,将这个触发:
virtual ~ILog() { delete monkey; }
当然,这将触发。 – Truncheon 2011-12-22 21:59:04
可能重复[什么是未定义的引用/未解析的外部符号错误,以及如何解决它?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external- symbol-error-and-how-do-i-fix) – 2015-08-12 06:42:05