Class infromation about objects in TList

As a container, TList stores all its items as a TObject wrapped in some additional information for indexing. If I have a TList of items from various classes, is it possible to find out the class of each item? For example,

TString* foo = "I'm a string";
TNtuple* bar = new TNtuple();
TList myList = new TList();
myList->Add(foo);
myList->Add(bar);

TIter next(myList);
TObject* obj;
while (obj = next())
{
  if (obj->WasATString())
    {
      std::cout << (TString) (*obj) << "\n"; // what replaces WasATString()?
    }
}

Ideally this code goes through myList and picks out only the objects of a certain type. Is there a way to do that?

Hi,

See TObject::InheritsFrom(const char* classname)

EDIT: You can also use something like: if (obj->IsA() == TString::Class())
Cheers, Bertrand.

Wow, that’s really useful! I’m not sure how I missed that in the documentation. Thanks!