Re: [ROOT] Shared function library.

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Wed Oct 25 2000 - 08:24:52 EDT

  • Next message: Jens Ivar Jordre: "Re: [ROOT] Shared function library."

    Hi Jens-Ivar, 
    
    Global variables is frowned upon in BRAT. Rather, you should use
    static members. For example, see BrDectectorTable, all the managers
    and so on. In fact, this will solve your problem in a much simpler way
    then using "R__EXTERN" and "#pragma link C++ global". 
    
    Here's a small example
    
           #include <iostream.h>
    
           class Analyser {
           private:
             static Analyser* fgInstance; // The static instance
             static Int_t     fgInteger;  // static integer (sort of global)
           public:          
    	 Analyser() { fgInstance = this; }
             
    	 static Analyser* Instance() { 
               if (!fgInstance) fgInstance = new Analyser; return fgInstance; }
    	 static Int_t& GetInteger() const { return fgInteger; }  
           }
    
           Analyser* Analyser::fgInstance  = 0;
           Int_t     Analyser::fgInteger   = 1;
    
           main() {
             if (Analyser::GetInteger() == 1) 
    	   cout << "Good" << endl;
    
    	 Analyser::GetInteger() = 10;
      
             Analyser* analyser = Analyser::Instance(); 
    
             if (analyser->GetInteger() == 10) 
    	   cout << "Also good" << endl;
    
             analyser->GetInteger() = 5; 
    
             if (Analyser::GetInteger() == 5) 
    	   cout << "Still good" << endl;
           } 
    
    Yours, 
    
    Christian  -----------------------------------------------------------
    Holm Christensen                             Phone:  (+45) 35 35 96 91 
      Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
      DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
      Denmark                                    Email:       cholm@nbi.dk
    



    This archive was generated by hypermail 2b29 : Wed Oct 25 2000 - 08:34:58 EDT