adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <new>
    #include <iostream>
    using namespace std;
    struct A 
    {
        virtual ~A() {  };
        void operator delete(void* p) 
        {
            cout << "A :: operator delete" << endl;
        }
    };
    struct B : A 
    {
        void operator delete(void* p) 
        {
            cout << "B :: operator delete" << endl;
        }
    };
    int main() 
    {
        A* ap = new B;
        delete ap;
    }

a.

A::operator delete

b.

B::operator delete

c.

Both A::operator delete & B::operator delete

d.

None of the mentioned

Answer: (b).B::operator delete

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?