-
What is the output of this program?
#include <iostream>
using namespace std;
struct OperatorA
{
virtual ~OperatorA()
{
cout << "~OperatorA()" << endl;
}
void operator delete[](void* p, size_t)
{
cout << "Operator A :: deleteed" << endl;
delete [] p;
}
};
struct OperatorB : OperatorA
{
void operator delete[](void* p, size_t)
{
cout << "Operator B :: operator deleteed" << endl;
delete [] p;
}
};
int main()
{
OperatorA* ptr = new OperatorB[2];
delete[] ptr;
};
-
- ~OperatorA()
~OperatorA()
Operator A :: deleteed - ~OperatorA()
~OperatorA() - ~OperatorA()
Operator A :: deleteed - Operator A :: deleteed
~OperatorA()
~OperatorA() - None of these
- ~OperatorA()
Correct Option: A
In this program, the behavior of the statement delete[] ptr is undefined.