Function doesn't retrun object

Hello there!

I ran into a problem concerning void-functions in ROOT. I tried to create five directory files and add the same list with a histrogram in it to each of them. The tricky part there is, that the sampled entries for the histrograms had to be different for each directory. (This is an assignement given to me by my supervisor at university, so don’t wonder about it.) My idea was to create an external function that is summoned each time I add the list to a directory.

void MakeList(TF1 *f){
TH1D *h1 = new TH1D(“h1”,“Histogram of my favourite function”,10,0.,1.);
for (int i=0;i<10000;i++) {h1->Fill(f->GetRandom());}
h1->SetDirectory(0);
TList *main_list = new TList();
main_list->SetName(“main_list”);
main_list->Add(h1);
return main_list;
}

This is the void I thought up. Note, that TF1 *f is defined in the following bit:

int Assignement_4(){
TF1 *f = new TF1(“f”,“sin(TMath::Pi()*x)”,0.,1.);
TFile *file = new TFile(“Assignement_4.root”,“recreate”);
TDirectoryFile *SUBDIR_0 = new TDirectoryFile(“SUBDIR_0”,“SUBDIR_0”);
TDirectoryFile *SUBDIR_1 = new TDirectoryFile(“SUBDIR_1”,“SUBDIR_1”);
TDirectoryFile *SUBDIR_2 = new TDirectoryFile(“SUBDIR_2”,“SUBDIR_2”);
TDirectoryFile *SUBDIR_3 = new TDirectoryFile(“SUBDIR_3”,“SUBDIR_3”);
TDirectoryFile *SUBDIR_4 = new TDirectoryFile(“SUBDIR_4”,“SUBDIR_4”);
SUBDIR_0->Add(MakeList(f));
SUBDIR_1->Add(MakeList(f));
SUBDIR_2->Add(MakeList(f));
SUBDIR_3->Add(MakeList(f));
SUBDIR_4->Add(MakeList(f));
SUBDIR_0->Write(SUBDIR_0->GetName(),TObject::kSingleKey);
SUBDIR_1->Write(SUBDIR_1->GetName(),TObject::kSingleKey);
SUBDIR_2->Write(SUBDIR_2->GetName(),TObject::kSingleKey);
SUBDIR_3->Write(SUBDIR_3->GetName(),TObject::kSingleKey);
SUBDIR_4->Write(SUBDIR_4->GetName(),TObject::kSingleKey);
}

I’m aware this is not the most elegant way of doing this. Now my problem is with the SUBDIR_0->Add(MakeList(f));-part. When executing I get the error message passing argument to parameter 'obj' here, which I don’t understand. Doesn’t MakeList(TF1 *f) as it is defined return an object?

Thanks a lot in advance!
Cheers,
Adrian

ROOT Version: 5
Platform: Windows 10
Compiler: ROOT Object Browser


TList *MakeList(TF1 *f) {
void Assignement_4() {

1 Like