TClass::New - safe ussage for arbitrary class?

Hi,
I’m using TClass::New() in one of my projects right now, and it seems to be working, but given some of the comments I’ve seen on this board I’m a little scared of it. So…

Say I have a object that derives from TSelector: class MySel : public TSelector {... };
am I safe (always safe, no matter what) writing the following? TClass *c = TClass::GetClass("MySel"); TSelector *s = reinterpret_cast<TSelector*>(c->New());

In general, say I have a TClass object, and the class it represents I know inherrits from TObject - but I know nothing more - not how many other classes inherrit from TObject, or how the multiple inherritance hierarchy looks, etc. Further, as above, at compile time I don’t know the type that I can tell the compiler about… is there any way I can safely write the following? If not, what can I write to get the TObject pointer? TObject *o = reinterpret_cast<TObject*>(c->New());

Many thanks in advance!

Cheers,
Gordon.

Hi Gordon,

[quote]In general, say I have a TClass object, and the class it represents I know inherrits from TObject …[/quote]TClass::New always returns the starting address of the object, so use:TClass *c = TClass::GetClass("MyType"); TObject *obj = reinterpret_cast<TObject*>( c->DynamicCast( TObject::Class(), c->New() ) );

Cheers,
Philippe.

Thanks!