I got this interface, which I wrote:
#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
Methods are purely virtual and therefore must be implemented by getting classes. If I try to create a class that inherits this interface, I get the following linker errors:
Undefined reference to ILog::ILog Undefined reference to ILog::~ILog
I understand why a virtual destructor exists (to make sure the derived destructor is called), but I do not understand why I get this linker error.
EDIT: Okay, so I need to define a virtual destructor as well. But can I still run the material in the definition of a virtual destructor, or will it just call the destructor of the derived classes and skip it? For example, this trigger:
virtual ~ILog() { delete monkey; }
source share