473,804 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creation of static during destruction

hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?

Thanks
Raja

Dec 21 '06 #1
5 1449
Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.
No. It's an error. B cannot be instantiated.

Dec 21 '06 #2
Parapura Rajkumar wrote:
class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?
I think it's unspecified.

The Standard (as I read it) says that the destruction of 'a' will
happen before B::~B returns (since it was constructed after 'b',
it has to be destroyed completely before 'b' is), however, it is known
that calling d-tors for static objects is done by registering them
with 'atexit' (although it is not explicitly specified by the Standard),
and the Standard does not specify what happens if you [try to] register
a function with 'atexit' while another function previously registered
with 'atexit' is executed during the program termination.

You might want to ask about it in comp.std.c++, refer to 3.6.3, 18.3,
6.7.

I say, try to avoid situations like that if possible.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Dec 21 '06 #3

Rolf Magnus wrote:
Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.

No. It's an error. B cannot be instantiated.
Why is that.. i omitted the public to keep the post terse

Dec 21 '06 #4
Rolf Magnus wrote:
Parapura Rajkumar wrote:
>hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior.

No. It's an error. B cannot be instantiated.
Oh, come on!
Dec 21 '06 #5

Parapura Rajkumar wrote:
hey all

class A
{

};
class B
{
~B()
{
static A a;
}
};

static B b;

Is this undefined behavior. or the standard seems to handle this case
as well ?

Thanks
Raja

what is the use of this......B destructor will be called when B process
is complete...

Dec 22 '06 #6

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

Similar topics

5
2749
by: Marijn | last post by:
I'd like to know how compilers usually handle static variables that are declared inside a function (as opposed to static class-members). Like in: int counter(){ static int c=0; ++c; return c; }
4
1573
by: Gianni Mariani | last post by:
What does the standard say about this code ... #include <iostream> const char * func( const char * v ) { std::cout << "func called with v = " << v << "\n"; return v; }
3
3408
by: John Ratliff | last post by:
When I dereference a pointer, does it make a copy of the object? Say I had a singleton, and wanted an static method to retrieve it from the class. class foo { private: static foo *bar; foo() {} // no public creation!
1
1465
by: Arnaud Debaene | last post by:
Hello, I think I found a bug in VC 7.1 concerning destruction of stack objects when linking a static, non managed, C++ library within a managed C++ application. Here is a repro case : 1) Build a static, unmanaged, library containing the following 2 files. Compiles with /MDd. // FILE BaseHolder.h #pragma once
4
1801
by: ma740988 | last post by:
Referencing source snippet below, the actual contruction of the foo objects is done in a class. In that regard, I chose methods, class1_construct and class2_construct for demonstration purposes. That aside, I encountered source akin to what's shown below today and I was almost convinced the source is wrought with trouble. On second thought it appears legal. The static ptr_foo object and it's use in assignment to other foo objects (ptr_1...
55
6274
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in C# in some way? Or maybe no, because it is similar to a global variable (with its scope restricted) which C# is dead against? Zytan
14
2590
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used in severel 'underwater operations' * there is a list which stores objects of class B There are several issues I'm not sure about:
5
1287
by: cctv.star | last post by:
I need to maintain certain data structure, shared by all instances of a class, declared as . This data structure must change whenever a new object is created or an existing object is destroyed. So I declared a static field with attribute. Now I need to add some code into all places where objects are created and destroyed. This class has 2 ctors: one default, and another taking parameters. I've found out, to my surprise, that new...
31
3419
by: Tom P. | last post by:
I am doing quite a bit of custom painting and it means I have to create a lot of brushes (think one for every file system object in a directory) per paint. How expensive is this? Should I find a way to create the brushes once, store them in an member variable, and use them when I need them? Or is creating brushes a throw-away process that doesn't take a lot of work? Thanks for the info. Tom P.
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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
10594
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
9166
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...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5529
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
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.