# Function doesn't retrun object

**URL:** <https://root-forum.cern.ch/t/function-doesnt-retrun-object/37074>\
**Category:** Newbie\
**Created:** [December 5, 2019, 1:29pm UTC](https://root-forum.cern.ch/t/function-doesnt-retrun-object/37074 "2019-12-05T13:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian\_bl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@adrian\_bl](https://root-forum.cern.ch/u/adrian_bl)\
**Post date:** [December 5, 2019, 1:29pm UTC](https://root-forum.cern.ch/t/function-doesnt-retrun-object/37074/1 "2019-12-05T13:29:56Z")

</div>

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

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 5, 2019, 3:30pm UTC](https://root-forum.cern.ch/t/function-doesnt-retrun-object/37074/2 "2019-12-05T15:30:16Z")

</div>

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