为何virtual析构函数不能是protected?

如下例:

class Base
{
public:
    
virtual foo() = 0;
protected:
    
virtual ~Base(){};
};

class Derived
{
public:
    Derived(string str) : _str(str){}
    
virtual foo(){ //.. }
protected:
    
string _str;
}


这时,如果有
Base *p = new Derived("some string");
//...
delete p;

这时,不能调用析构函数

posted @ 2007-09-09 19:33  中土  阅读(1138)  评论(1)    收藏  举报
©2005-2008 Suprasoft Inc., All right reserved.