Get the value and type of a member of a TObject derived class

Hi,

I have a class deriving from a TObject, I know the name of the data members, that I can obtain using ie.

myClassInstance->IsA()->GetListOfDataMembers()

Now, which is the best way to obtain the value/type from a member knowing its name? I.e. “myDataMember”

There is a method like the following ones?

myClassInstance->GetDataMemberValue( “myDataMember” )

And then to know the type, Double_t, Int_t, TString

myClassInstance->GetDataMemberType( “myDataMember” )

Thanks!

Hi,

TClass *cl = myClassInstance->IsA(); TDataMember *dm = (TDataMember *)cl->GetListOfDataMembers()->FindObject("myDataMember"); if (dm) { cout << dm->GetFullTypeName() << endl; TDataType *dt = dm->GetDataType(); cout << dt->GetFullTypeName() << endl; cout << dt->GetType() << endl; }
See the TDataMember and TDataType classes documentation

Cheers, Bertrand.