Instantiate a derived class using its name

Hi,

I have a library (lets say myLibrary,so) which is rootified, all the classes inside derive from TObject, and implement ClassDef and ClassImp. Therefore, I can load it in root using gSystem->Load(“myLibrary”);

I have a base class named for example TBaseClass, and I want to Instantiate and get a pointer to a derived class (lets say TDerivedClass) inhereting from TBaseClass.

This might be a very basic question, but
[b]I would like to use the TDerivedClass name to do something equivalent to this:

TBaseClass *b = (TBaseClass *) gSystem->GetLibrary(“myLibrary”)->Instantiate(“TDerivedClass”);[/b]

It is this possible and/or an easy way to do it?

I am in ROOT 5.

Thanks,
Javier

Hi Javier,

did you try the TClass::New method?

TClass* c = TClass::GetClass("myClass");
myMotherClass* mmc = (myMotherClass*) c->New();

Cheers,
D

Ok, thank you! This is exactly what I was looking for.