473,662 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3850
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**********@Ho me.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_durati on_.

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.c om 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
1894
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
1621
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. However, when the copy of the object inside the function is destroyed, its destructor is called. By default, when a copy of an object is made, a bitwise copy occurs.
7
2263
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
3801
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 example ... C# Essentials (O'Reilly) - "Finalizers are class-only methods". Not sure what "class-only method" means in this context, but ususally I would assume that to mean it is static and would only be called once for the life of the...
20
7499
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, but this seems to rely on a call from the application, e.g. MyClass.Dispose()
9
6051
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 manager and I can not launch anything from the desktop (eg. a web shortcut) without firt killing this process. The object is launched using JScript with the following code: var Launcher = new ActiveXObject("LaunchControl");
11
1978
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 ClassA { public: ClassA()
11
3247
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 my object is destroyed, I want my object to un-register this event. If I don't then the object would never be destroyed until the object I passed in the constructor is destroyed. I have implemented a Dispose(), Dispose(bool), and ~Finalize...
1
1519
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 a C++/ME console application that calls F() and catches all exceptions with a "catch(...)" filter. The thing that I dont understand is why doesn't the auto object created on stack get destroyed. See my sources: Project 1. Unmanaged lib....
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.