How many times ~A() destructor will be called in the following code?
#include <stdexcept>
class A
{
public:
    ~A(){ }
};

class B
{
    A *a;
public:
    B() {
        try {
            a = new A[100];
            throw std::logic_error("oups");
        }
        catch(...){ throw; }
    }
    
    ~B(){ delete [] a;}
};

int main()
{
    try {
        B b;
        A a[10];
        A *a2 = new A();
        delete a2;
    } catch(...) { }
    return 0;
}

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes