2

我有一段代码(来自 DLL),如下所示:

class A {
    public:
        virtual ~A();
};

class B : public A {
    public:
        ~B();
}

~A() {
    // #1
}

~B() {
    // #2
}

当我使用delete an_instance_of_B我得到scalar deleting destructor. 任何解决方法?

4

1 回答 1

10

不要delete实例化B. 您应该delete在指向分配有的对象的指针上使用new

B b;
delete b;   //wrong

//.........

B* pB = new pB;
delete pB;  //okay

//.........

B justThis; //best
于 2013-05-03T08:03:19.603 回答