Yves Jaradin <[email protected]> writes:

>> not sure what you mean here.  could this have to do with the placement
>> argument to the new operator?
>>
>>      new (ptr) X(v1,...,vn)
>>
>
> That is related to it. Basically if you have an A* and want a B*, you have to
> find out the beginning of the memory block in which A is, give that to the
> placement new and hope that the numeric value of the pointer you get back is
> equal to the one you started with.

you can overload new where appropriate:

    void* operator new(size_t,void* p) { return p; }

> Finding the beginning of the memory for the
> A object is implementation specific and error-prone if one wants to consider
> all cases including when the dynamic type of the object pointed to is a
> subclass of A.

since we are talking about polymorphic classes, dynamic_cast<void*>(p)
is garanteed to return a pointer to the "complete" object containing *p
(you could even used a virtual base class to provide a method to return
that address).  you can then pass that pointer as the placement argument
for new.

Cheers,

--Denys
_________________________________________________________________________________
mozart-hackers mailing list                           
[email protected]      
http://www.mozart-oz.org/mailman/listinfo/mozart-hackers

Reply via email to