Passing a histogram in a function

Hi everyone,

I’m trying to do something that seems quite simple but I can’t find the right syntax anywhere and I’m not even sure it’s feasible.

I’m basically trying to pass a histogram in a function, has shown in the code below:

void test()
	TH1F *h1 = new TH1F("h1","Histo from a Gaussian",100,-3,3);

	double mean_f = mean_function(h1);

double mean_function(TH1F** histo)
	return histo->GetMean();

When running it, I get the following error:
Error: non class,struct,union object histo used with . or -> test.C:12:

So it seems that my function is not well defined. How should I write it then?

Thank you very much :slight_smile:

ROOT Version: 5.34/36
Platform: Ubuntu 16.04
Compiler: C/C++ 5.18.00

Just drop one of the 2 ‘*’ in the signature of ‘mean_function’.

as @sbinet said, you are defining mean_function to take a pointer to pointer to TH1F as argument (one “pointer” per “*” in the argument type). Instead you just want to take a pointer to TH1F, i.e. a TH1F*.


Thank you very much, I didn’t realize I had put an extra star…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.