Re: Pointer Issues

From: Rene Brun <brun_at_pcroot.cern.ch>
Date: Wed, 22 Jun 2005 07:12:44 +0200 (MEST)


Chris,

Replace

    void getHIST(TH1F* hist, int i) {
by

    void getHIST(TH1F*& hist, int i) {
and

    cout << " hist = " << emechist << endl; by

    cout << " hist = " << hist << endl;

Rene Brun

On Tue, 21 Jun 2005, Christopher
James
Schilling wrote:

> Hi, I have the following, relatively simple piece of code that I am trying
> to run in Root, V4.03/02 on SL3.
>
> #include "TFile.h"
> #include "TString.h"
> #include "TH1.h"
> #include "iostream.h"
>
> TFile* f=new TFile("./DAT/slg_ecalc.root");
>
> void getHIST(TH1F* hist, int i) {
> TString emcobj;
> emcobj = "emc1"; emcobj+=i;
> hist = (TH1F*)f->Get(emcobj);
> //hist->Draw();
> }
>
> void get() {
>
> TH1F* hist;
> getHIST(hist, 2);
> cout << " hist = " << emechist << endl;
> hist->Draw();
>
> }
>
> If I issue the command
>>>> root -l get.C -q
> I get the following output
>
> emechist = 0
> Error: illegal pointer to class object emechist 0x0 191 FILE:get.C LINE:20
>
> If I issue the command (trying to Compile)
>>>> root -l get.C+ -q I get a segmentation violation:
>
> emechist = 0
>
> *** Break *** segmentation violation
> Generating stack trace...
> 0x004e5b02 in <unknown> from /u2/schilling/slg/./get_C.so
>
> It seems as if the histogram is out of scope outside the function. The funny
> thing is if I change
> void getHIST(TH1F* hist, int i) to void getHIST(TH1F&* hist, int i)
> the macro works, and the histogram is drawn, but I cannot compile since it is
> illegal to have a pointer to a reference.
>
> Any ideas??
> Cheers
> Chris S
>
Received on Wed Jun 22 2005 - 07:12:50 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:09 MET