subramanian napsal:
Quote:
Suppose I have the following class:(shown only partially. Assume proper
ctors and dtors):
>
class Date
{
...
>
static Date temp_date;
static Date another_date;
>
...
};
>
Date Date:temp_date;
Date Date::another_date;
>
int main(void)
{
...
>
return 0;
}
>
QUESTION:
1)What will be the order of destructor calls for temp_Date and
another_date.
>
2)Does the Standard C++ define the order of evaluation of these objects
in this situation or is it compiler dependent ?
|
In your example Date:temp_date will be created before
Date::another_date and destruction will proceed in reverse order. It
depends on order in which you will write it, so if you change it to
Date Date::another_date;
Date Date::temp_date;
the order of creation and destruction changes too. It is guaranteed by
standard for case that all such statements are in one translation unit
(that usualy means in one source file). if you place Date::another_date
in one source file and Date::temp_date in another source file, the
order of construction and destruction is not guaranteed at all. It may
be different in different cases even in one compiler.