我对多个虚拟析构函数产生了一些疑虑,尤其是在阅读了http://blogs.msdn.com/b/oldnewthing/archive/2004/05/07/127826.aspx之后。假设我有:
class Base
{
public:
Base();
virtual ~Base();
private:
Logger* _logger;
};
//and
class Derived : public Base{
public:
Derived();
virtual ~Derived();
private:
Logger* _logger;
};
在 CPP 文件中,每个析构函数都会删除相应的
_logger
指针。Base::~Base(){ //base.cpp
delete _logger;
}
Derived::~Derived(){ //derived.cpp
delete _logger;
}
这个是否能按我的意图成功运行,而且没有内存泄漏?