Th1f in a structure


I am trying to create a structure containing TH1F histo

[code]void main(){

 struct a{
        TH1F h;} b;
       b.h(" ", " ", 10, 0, 10);}


but the constructor doesn’t work… why? which is the correct way to call it?


this is illegal C++: for the compiler you are trying to call a method of the histogram (default constructed) with 5 arguments, two const char* and 3 ints.
To achieve what I think you are aiming to, you should implement a class and initialise the contained histogram in the constructor.

hi danilo, thanks for your advice!

If i use a pointer the constructor seems to work

[code]void main(){

 struct a{
        TH1F *h;} b;

       b.h=new TH1F(" a", "a ", 10, 0, 10);

b.h->Draw(); }[/code]

also the Fill function seems to work. But there is problem when I call Draw function…

What problem?

root crashes…

so I will follow the advice you gave me! thanks!