Re: [ROOT] Problem with inheritance from TGraph

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Aug 16 2002 - 16:57:51 MEST


Hi Matt,

I do not see any problems with your class. I created two files

//file ThresholdCurve.h
#include "TGraph.h"
   
class ThresholdCurve:public TGraph {
 public:
    bool calib;                  // Threshold calibrated?
    bool ismod;                   // Is it a module?
    int id;                      // Module (or plane if a plane) id
    ThresholdCurve() {id = 0; calib = true; ismod = true;}
    virtual ~ThresholdCurve() {}
    void SetCalib(bool c = true) { calib = c;}
    bool GetCalib() {return calib;}
    void SetId(int i) {id = i;}
    int  GetId() {return id;}
    void SetIsMod(bool m) {ismod = m;}
    bool GetIsMod() {return ismod;}
ClassDef(ThresholdCurve, 1)
};

and

//ThresholdCurve.cxx
#include "ThresholdCurve.h"
   
   ClassImp(ThresholdCurve)

then ran the following Root session without problems
root > .L ThresholdCurve.cxx++
root > t = new ThresholdCurve
root > t->Inspect()

and I get the Inspect canvas from which i produce the inspect.gif file
in the attachement.

Rene Brun

On Fri, 16 Aug 2002, Matt Palmer wrote:

> Hi, 
> I have a very bizarre problem:
> I have a class which derives from TGraph:
> class ThresholdCurve:public TGraph {
>  public:
>     bool calib;                  // Threshold calibrated?
>     bool ismod;                   // Is it a module?
>     int id;                      // Module (or plane if a plane) id
>     ThresholdCurve() {id = 0; calib = true; ismod = true;}
>     virtual ~ThresholdCurve() {}
>     void SetCalib(bool c = true) { calib = c;}
>     bool GetCalib() {return calib;}
>     void SetId(int i) {id = i;}
>     int  GetId() {return id;}
>     void SetIsMod(bool m) {ismod = m;}
>     bool GetIsMod() {return ismod;}
> ClassDef(ThresholdCurve, 1)
> };
> 
> The ClassImp macro is in the .cpp file
> 
> I compile this as part of a shared object library and load it into root:
> 
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   3.03/07     6 August 2002   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
>  
> FreeType Engine v1.x used to render TrueType fonts.
> Compiled for linuxicc with thread support.
>  
> CINT/ROOT C/C++ Interpreter version 5.15.51, July 19 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .L libTB2001.so
> root [1] t = new ThresholdCurve
> (class ThresholdCurve*)0x87dea38
> root [2] gDebug = 1000
> (const int)1000
> root [3] t->Inspect()
> SetTextSize: -1.000000
>  
>  *** Break *** segmentation violation
> Root > SetTextSize: -1.000000
> 
> And as you can see, there is a seg violation.  If I change the inheritance to:
> class ThresholdCurve: TNamed {
> //as above
> };
> 
> Then it works fine
> Changing it again to:
> class ThresholdCurve: TNamed, TAttFill {
> //as above
> };
> gives the same error as above.  Does anyone have any idea what might be 
> wrong?  I suspect that it is something to do with the multiple inheritance 
> from classes that don't derive from TObject, but I couldn't see anything 
> special in the TGraph class to make it work.
> 
> Thanks
> Matt
> 



inspect.gif



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:04 MET