creation of static during destruction

P

Parapura Rajkumar

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
 
R

Rolf Magnus

Parapura said:
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.
 
V

Victor Bazarov

Parapura said:
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
 
Y

Yahooooooooo

Parapura said:
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top