473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

When does the destructor of a static object gets called?

Hi,

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

Thank you.

Mar 10 '06 #1
8 3842
On 10 Mar 2006 08:08:08 -0800, Al************@gmail.com 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
No**********@Home.com
Mar 10 '06 #2
Al************@gmail.com 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
Mar 10 '06 #3
Hi!

Al************@gmail.com:
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
Mar 10 '06 #4
Matthias Kluwe wrote:
Al************@gmail.com:
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
Mar 10 '06 #5
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)

Mar 10 '06 #6
ri*****@email.com 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
Mar 10 '06 #7
are you suggesting the destructor is never called?

Mar 13 '06 #8
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...
Mar 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Douglas Peterson | last post by:
Take a look at this code, it looks funny as its written to be as short as possible: -- code -- struct Base { ~Base() { *((char*)0) = 0; } }; struct Derived : public Base
9
by: ceo | last post by:
Hi there, I'm reffering to a text that says following: "To summarize: When a copy of an object is generated because it passed to a function, the object's constructor function is not called....
7
by: cgamache | last post by:
Which is a more correct statement? A destructor runs automatically when an object is deallocated. or A destructor runs automatically immediately before an object is deallocated.
4
by: Joe | last post by:
I am looking for the quintessential blueprint for how a C++ like destructor should be implemented in C#. I see all kinds of articles in print and on the web, but I see lots of discrepencies. For...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
9
by: Simon | last post by:
Hi, I have written an ActiveX object to resize images and upload them to a database, this all works fine but when I close internet explorer the process iexporer.exe is still running in my task...
11
by: AB | last post by:
Hi All, I've got an array of objects, during the execution of the program I'd like to assign a particular object to a certain element in the object array. The sample code's like this... class...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
1
by: caa | last post by:
I have made a simple text example. I have two projects. First is an unmanaged static lib, containing function F(), which created an object of type A and throws an exception. The second project is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.