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

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,059
Members
48,769
Latest member
Clifft

Latest Threads

Top