destructor

R

Ramkey

I was asked in a test
class A{
A ~A{
cout << "A's destructor";
}
};

int main(void){
A Aobj;
Aobj.~A;
}

What will be the output?

I wrote "A's destructor";
I think it may also be "A's destructor" "A's destructor:(twice).I
didnt run the program.What will be the output and why?

Thanks
 
R

Rolf Magnus

Ramkey said:
I was asked in a test
class A{
A ~A{
cout << "A's destructor";
}
};

int main(void){
A Aobj;
Aobj.~A;
}

What will be the output?

I wrote "A's destructor";
I think it may also be "A's destructor" "A's destructor:(twice).I
didnt run the program.What will be the output and why?

Ignoring the syntax errors in your code, the output is undefined. Attempting
to destroy an object twice has undefined behavior.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top