C++ segmentation fault: getting member pointer

102 Views Asked by At

My class contain pointer to the histogram object (from ROOT framework). I would like to after filled return it, but segmentation fault is occurring.

// header
class PedestalSubstractorModel
{
    TH2D* histo;
 public :


  PedestalSubstractorModel();
  virtual void     Fill();
  virtual TH2D*     GetHisto(){return histo; }


};

main.cpp

#include"PedestalSubstractorModel.h"
#include<iostream>
int main(int argc, char * argv[])
{

    PedestalSubstractorModel *p=new PedestalSubstractorModel();
    p->FILL();
    std::cout<<p->GetHisto()->GetRMS()<<endl;

    return 0;
}

What should I do to avoid this error.

Best Regards :)

0

There are 0 best solutions below