Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > When does the destructor of a static object gets called?

Reply
Thread Tools

When does the destructor of a static object gets called?

 
 
Allerdyce.John@gmail.com
Guest
Posts: n/a
 
      03-10-2006
Hi,

Can you please tell me when does the destructor of a static object gets
called?

Thank you.

 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      03-10-2006
On 10 Mar 2006 08:08:08 -0800, wrote:

>Hi,
>
>Can you please tell me when does the destructor of a static object gets
>called?
>
>Thank you.


Why do you ask here? It's in your textbook, isn't it?

--
Bob Hairgrove

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      03-10-2006
wrote:
> Can you please tell me when does the destructor of a static object gets
> called?


At some point after 'main' has returned.

V
--
Please remove capital As from my address when replying by mail
 
Reply With Quote
 
Matthias Kluwe
Guest
Posts: n/a
 
      03-10-2006
Hi!

:
> Can you please tell me when does the destructor of a static object gets
> called?


You mean objects in unnamed namespaces like

#include <iostream>
#include <ostream>

class A {
public:
~A() { std::cout <<"~A"; }
};

namespace {
A a;
}

int main() {
return 0;
}

What do you guess? Did you try out?

Regards,
Matthias
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-10-2006
Matthias Kluwe wrote:
> :
>
>>Can you please tell me when does the destructor of a static object gets
>>called?

>
>
> You mean objects in unnamed namespaces [...]


I would guess 'no'. Usually "a static object" means an object with static
_storage_duration_.

V
--
Please remove capital As from my address when replying by mail
 
Reply With Quote
 
rino100@email.com
Guest
Posts: n/a
 
      03-10-2006
A static object is created as the programs starts to run upon
allocation of all global variables... therefore it is destroyed when
all global variables are deallocated (ie. at program exit)

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-10-2006
wrote:
> A static object is created as the programs starts to run upon
> allocation of all global variables... therefore it is destroyed when
> all global variables are deallocated (ie. at program exit)


A static object can be declared inside a function, and be never created
if that function is never called. And as a result, such object is never
destroyed. How 'bout that?

V
--
Please remove capital As from my address when replying by mail
 
Reply With Quote
 
Diego Martins
Guest
Posts: n/a
 
      03-13-2006
are you suggesting the destructor is never called?

 
Reply With Quote
 
Ben Pope
Guest
Posts: n/a
 
      03-13-2006
Diego Martins wrote:
> are you suggesting the destructor is never called?


Please quote what you are referring to.

He is saying that the object may never be constructed. In that case,
the destructor will not be called, of course.

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie -- smart pointer destructor called without destructor everbeing called Jimmy Hartzell C++ 2 05-20-2008 02:20 AM
newbie -- smart pointer destructor called without destructor everbeing called Jimmy Hartzell C++ 0 05-19-2008 07:05 PM
compiler generated destructor vs class implemented destructor arun C++ 2 06-13-2006 05:43 AM
Problem: shared object loading runs constructor of a static object, but static linkage does not. tropos C++ 3 11-30-2005 04:54 PM
Explicit destructor calls from inside base class destructor frs C++ 20 09-21-2005 09:22 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57