dan
dan

Reputation: 53

Scalar deleting destructor

I have a piece of code (from a DLL) that looks like this:

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

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

~A() {
    // #1
}

~B() {
    // #2
}

When I use delete an_instance_of_B I get scalar deleting destructor. Any workarounds?

Upvotes: 2

Views: 11235

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258598

Don't delete an instance of B. You're supposed to use delete on pointers to object allocated with new:

B b;
delete b;   //wrong

//.........

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

//.........

B justThis; //best

Upvotes: 10

Related Questions