clear() and UFCS

Jonathan M Davis jmdavisProg at gmx.com
Fri May 25 19:46:43 PDT 2012


On Saturday, May 26, 2012 04:34:30 Mehrdad wrote:
> Okay, thanks for the explanation.
> 
> So basically, clear() just calls __dtor(), and then zeros out the
> vtable?

Yes, though it calls rt_finalize on classes rather than dtor directly, so that 
may do some extra stuff beyond strictly calling __dtor and zeroing out the 
vtable.

> I don't understand what you mean by "I don't believe that it
> destroys what the object references"... why should clear() ever
> destroy anything except the object that it's destroying?

Normally when an object is destroyed, all of its member variables' destructors 
would be called as well (at least for member variables which are structs or 
arrays of structs - member variables which are classes aren't finalized). But 
the destructor itself doesn't call all of the member variables' destructors, 
so calling __dtor doesn't call them. You have to do something else to get the 
member variables destroyed as well (something with typeid I think, but I don't 
remember the details).

- Jonathan M Davis


More information about the Digitalmars-d mailing list