What kind of variable type are TH1, TH2, TGraph, TGraphErrors and TF1

Hi rooters
I’m creating this method:

void RootImprove::SetTitles(TH1 * h , const char * title , const char * titlex ,const char * titley)
{
  h->SetTitle(title);
  h->GetYaxis()->SetTitle(titley);
  h->GetYaxis()->CenterTitle();
  h->GetXaxis()->SetTitle(titlex);
  h->GetXaxis()->CenterTitle();

But I’d like that this method works as well for TH2, TGraph, TGraphErrors and TF1 but I don’t want to define five same structured methods, so that what kind of argument should be “h”, I’ve tried with a TObject, but is not working.

Any idea?
Thanks in advance

Hi,

perhaps you can resort to a widely spread C++ feature, templates:

template<typename T>
void SetTitles(T * h , const char * title , const char * titlex ,const char * titley)
{
  h->SetTitle(title);
  h->GetYaxis()->SetTitle(titley);
  h->GetYaxis()->CenterTitle();
  h->GetXaxis()->SetTitle(titlex);
  h->GetXaxis()->CenterTitle();
}

the compiler (interpreter if you are writing macros) will generate the “right” function for the pointer type you passed.

Cheers,
D