Re: [ROOT] TButton, static variable

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat May 19 2001 - 09:39:33 MEST


Hi Dmitriy,

The following sequence:
root [] .x nnn.C(1,2)
root [] .x nnn.C(2,2)

should give the same result "1", not 1,2

When you execute a script with
  .x nnn.C(..)
cint will always reinterpret the file nnn.C

If you want to increment a global variable, this variable should be
defined
externally, or alternatively, instead of using ".x nnn.C", you can do
  root > .L nnn.C
then
  root > nnn(1,2);

Rene Brun


On Fri, 18 May 2001, Dmitriy Bandourine wrote:

> 
> Hi ROOTers,
> 
> I create the TButton object by
> TButton *b = new TButton("Summary","gROOT->ProcessLine(\".x nnn.C(1,2)\");",0.1,0.8,0.3,0.9);
> 
> and define in "nnn.C" script static variable "count":
>  
> nnn.C(Int_t, Int_t)
> {
>   static Int_t count = 0;
>   cout << "count =" << ++count << endl;
> 
> [... omitted ...]
> }
> 
> Pressing on the button "b" I get "count = 0" (zero) everytime.
> But when I call nnn.C from command line:
> root [] .x nnn.C(1,2)
> root [] .x nnn.C(2,2)
> 
> I receive "1", "2" values for count.
> 
> Why "count" does not work properly in first case (through the button)?
> 
> 
>  - Dmitriy - 
> 



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:45 MET