Home » C++ Programming » Dynamic Memory » Question
  1. What is the output of this program?
    #include <iostream>
    #include <new>
    using namespace std;
    struct N
    {
    virtual ~N() { };
    void operator delete(void* ptr1)
    {
    cout << "N :: operator delete" << endl;
    }
    };
    struct M : N
    {
    void operator delete(void* ptr1)
    {
    cout << "M :: operator delete" << endl;
    }
    };
    int main()
    {
    N* ptr2 = new M;
    delete ptr2;
    }
    1. Compilation Error
    2. N :: operator delete
    3. M :: operator delete
    4. Runtime Error
    5. None of these
Correct Option: C

In this program, We are passing the value to the M, So we are printing M::operator delete.



Your comments will be displayed only after manual approval.