Purpose of IsA() method

Hi,

Pardon the naive question, I’m trying to see if there is something more complex here that escapes me.

What is exactly the purpose of the IsA() method? I understand that when we say

if(obj->IsA() == MyClass::Class())

we test if obj is of type MyClass.

I can think that this can be used with inheritance (or multiple inheritance) where a pointer may be pointing to more than one types. If that’s the case, then this is very similar to a dynamic_cast operation. Then, why go into the trouble of introducing the IsA() method?

–Christos

Hi Christos,
there’s a fundamental difference between dynamic_cast and IsA:

TH1F* h2=new TH1F("h","h",10,0.,1.); if (dynamic_cast<TH1*>(h2) && h2->IsA()!=TH1::Class()) std::cout<<"dynamic_cast and IsA() are different." << std::endl;
Also, IsA() gives access to the Cint’s RTTI, dynamic_cast does not. But if you know your compiler supports dynamic_cast, and you don’t need Cint’s RTTI, then use dynamic_cast wherever you can.
Cheers, Axel.