本题的代码:
#include <iostream>
using namespace std;
class Base
{
public:
Base() { cout<<"Base"<<endl; }
~Base() { cout<<"~Base"<<endl; }
};
class Derive : virtual public Base
{
public:
Derive() { cout<<" Derive"<<endl; }
~Derive() { cout<<" ~Derive"<<endl; }
};
int main(int argc, char* argv[])
{
Base * b = new Derive();
delete b;
return 0;
}
上面的delete将引发访存异常(VC6.0)。如果主函数里代码改为:
Derive * b = new Derive();
delete b;
return 0;
将不会有什么异常出现。