Re: Who calls my destructor?

Rene Brun (Rene.Brun@cern.ch)
Wed, 23 Sep 1998 02:04:21 +0200


Hi Reiner,
In order to build the TContextmenu object when you click with the
right mouse button, Root creates an object of your class
via the default constructor, look at the member functions callable
from the GUI, build the menu, then deletes the object.
This process happens only once for each class.
You should protect your destructors in case your object has been
created by the default constructor.

Rene Brun

ROHLFS Reiner wrote:
>
> Hi ROOTteam,
>
> I have a MainWin derived from TCanvas with a function that can be called from
> the "Right Mouse Menu". See program and header file below. But as soon as I
> call the DoNothing() - function from the mouse menu the destructor of my canvas
> class (MainWin) is called. You can control that by the outputs as well as in a
> debugger session.
>
> The LinkDef.h file:
> =================================================
> #ifdef __CINT__
>
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
>
> #pragma link C++ class MainWin;
>
> #endif
> =================================================
>
> The header file:
> =================================================
> #include <TCanvas.h>
>
> class MainWin : public TCanvas
> {
> public:
> MainWin(Text_t* name, Text_t* title, Int_t wtopx, Int_t wtopy, Int_t ww,
> Int_t wh)
> : TCanvas(name, title, wtopx, wtopy, ww, wh) {}
>
> MainWin() : TCanvas() {}
> ~MainWin();
> void DoNothing(); // *MENU*
> ClassDef(MainWin, 1)
> };
> ==================================================================
>
> and here the program:
> ==================================================================
> #include <TROOT.h>
> #include <TApplication.h>
>
> #include "+Y"
>
> extern void InitGui();
> VoidFuncPtr_t initFuncs[] = {InitGui, 0};
> TROOT root ("ISDC", "Display", initFuncs);
>
> main(int argc, char ** argv)
> {
> TApplication theApp("ISDC_OSM", &argc, argv);
>
> MainWin mainWin("Display", "Display", 10, 60, 900, 600);
>
> theApp.Run();
>
> }
>
> /////////////////////////////////////////////////////////////////////////
> /////////////////////////////////////////////////////////////////////////
>
> ClassImp(MainWin)
>
> /////////////////////////////////////////////////////////////////////////
> MainWin::~MainWin()
> {
> printf("Now we are in Destructor of MainWin\n");
> }
> /////////////////////////////////////////////////////////////////////////
> void MainWin::DoNothing()
> {
> printf("Now we are in DoNothing\n");
> }
> ================================================================