www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - casting objects

 From http://www.digitalmars.com/d/expression.html#UnaryExpression

"Any casting of a class reference to a derived class reference is done 
with a runtime check to make sure it really is a downcast."

it would be much more useful if this was:

"Any casting of a _reference_ to a class reference is done with a 
runtime check to make sure it really is _valid_ cast."

This should be easy to do. Have some sort of static member for each 
class the can recognize the vtbl pointer for any class that can be cast 
to it. This would allow for things like this:

class foo {...}

void* vp;

...// set vp (maybe to a foo)

foo fig  = cast(foo)vp;

if(null !is fig) writef("vp is a fig\n");


Thoughts? Comments?
Aug 17 2006