Re: Why '(&b) -> f() ' is static binding?
On Oct 23, 11:57 am, Erik Wikstr=F6m <Erik-wikst...@telia.com> wrote:
On 2007-10-23 11:25, James Kanze wrote:
[...]
I'm very sure that something like:
{
T var ;
// ...
var.~T() ;
new (&var) T ;
// ...
}
is legal and well defined (unless the constructor of T happens
to raise an exception). I'm less sure about changing the type.
3.8 =A77:
"If, after the lifetime of an object has ended and before the storage
which the object occupied is reused or released, a new object is created
at the storage location which the original object, a pointerthat pointed
to the original object, a reference that referred to the original
object, or a name of the original object will automaticalle refer to the
new object and, once the lifetime of the new object has started, can be
used to manipulate the new object, if:
* the storage of the new object exactly overlays the storage location
which the original object occupied, and
* the new object is of the same type as the original object (ignoring
the top-level cv-qualifiers), and
* the original object was a most derived object (1.8)of type T and the
new object is a most derived object of type T (that is, they are not
base class subobjects)."
To me it seems like all but the last condition (perhaps with an addition
for the cv-qualifiers) are superfluous, since most derived objects of
the same type should have the same size and are of the same size, but
there might be some subtle points I am missing.
I think they're also trying to disallow things like:
p->~B() ;
new ( p + i ) B ;
where the new object is created in the same storage, but with a
different start address. I think that the goal is (was) to
allow something like my example, but nothing else.
When all is said and done, given the possibility of exceptions
from a constructor, I'd say that there would really be no harm
in disallowing even my example. The simple answer is "don't do
it". Regardless of what the standard says.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34