Incorrect implementation of dynamic_cast<>

From: George Heintzelman (gah@bnl.gov)
Date: Wed Sep 01 1999 - 00:13:32 MEST


Hi,

I was playing around a bit with dynamic_cast<>, having read a bit more 
in Stroustrup, who says:

'dynamic_cast<T*>(p) looks at the object pointed to by p (if any). If 
that object is of class T or has a unique base class of type T, then 
dynamic_cast returns a pointer of type T* to that object; otherwise, 0 
is returned.'

This seems like very intuitive, useful, and meaningful behavior, and 
shouldn't be too hard to implement either, since you've already got 
dynamic type information running around.

However, if in ROOT I do:

class Base {
   int foo;
};

class Derived {
   int bar;
};

Derived *x = new Derived;
Base *y = dynamic_cast<Base *>(x);  // This works, as it should;
TObject *z = dynamic_cast<TObject *>(x); // This gives non-zero, 
					 // as it shouldn't!

George Heintzelman
gah@bnl.gov



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:39 MET