Re: POD destruction
"""kiryazev@gmail.com wrote:
"""
"""alex wrote:
"""
I wonder what is the practical ground for this? :-)
The practical ground may be something like this
#include <iostream>
struct POD
{
int i;
double d;
};
POD get_pod()
{
static POD pod = {10, 3.14};
return pod;
}
OK. If you are really going to use some POD-type there, probably, you
will not need that 'pod' be ever destructed, so you can get around with
something like this:
struct POD
{
int i;
double d;
POD(int i, double d) : i(i), d(d) {}
};
POD const& get_pod()
{
static POD const* pod = new POD(10, 3.14);
return *pod;
}
Anyway, I would not use any object (POD-type or not) after it's
destructor was called (except for later in-place construction with
placement new), since it's too tricky. Even if it was granted by the
standard to access POD objects after destruction what if you will need
to use some non-POD type in the place later?
If you are concerned with singleton techniques reading Alexandrescu
book "Modern C++ Design" (chapter on Singletons) might help.
--
Alex Shulgin
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]