Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   destructor (http://www.velocityreviews.com/forums/t621766-destructor.html)

Ramkey 06-23-2008 09:03 AM

destructor
 
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

Rolf Magnus 06-23-2008 10:54 AM

Re: destructor
 
Ramkey wrote:

> 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.


Rolf Magnus 06-23-2008 11:45 AM

Re: destructor
 
Dyziek wrote:

> Rolf Magnus pisze:
>> Ramkey wrote:
>>
>> Ignoring the syntax errors in your code, the output is undefined.
>> Attempting to destroy an object twice has undefined behavior.
>>

>
> it is not destroying object twice, it is running its destructor twice.


That's what "destroying the object" means.

> object is destroyed only once.


No. Its memory is deallocated once.



All times are GMT. The time now is 09:02 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.