jeudi 23 avril 2015

Passing an array into a function c++

so I'm having an issue passing an entire array of histograms into a function in C++

the arrays are declared like this

TH1F *h_histogram[2];
h_histogram[2] = new TH1F("h1", "h1", 100, 0, 100);

And here is what I'm trying to do in the function:

void overlayhists(TH1 *hists, int numhists) {
    int ymax = 0;
    for (int i=0; i<numhists; i++) {
        if (hist[i].GetMaximum() > ymax) {
            ymax = (hist[i].GetMaximum())*1.05;

And I'm passing the function an array like this overlayhists(*h_Energy, 2);

Where h_Energy is an 1D array with 2 elements. The code will run through the first histogram in the loop but as soon as it starts the second loop and tries to access hist[i].GetMaximum() on the second try it segfaults.

What gives?

Aucun commentaire:

Enregistrer un commentaire