How to create a global variable like gPad

Dear Rooters,

I am trying to create a program that has a class which allows me to update Histograms. I would like to access this class from the command line via a global variable like gPad.
Please see the attachment for an example. Here I create an instance of the class which I assign to a global variable. But when I want to access this global variable I get the following:

[code] *******************************************

  •                                     *
  •    W E L C O M E  to  R O O T       *
  •                                     *
  • Version 5.28/00 14 December 2010 *
  •                                     *
  • You are welcome to visit our Web site *
  •            *
  •                                     *

ROOT 5.28/00 (trunk@37585, Dec 14 2010, 15:20:27 on linuxx8664gcc)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] gHistUpdater
Error: Symbol gHistUpdater is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***

what do I need to do to be able to access the global variable?

Thank you,
exampleForRoot.tar.gz (15.3 KB)

search the Internet for “c++ singleton”.
For example: … ern-Part-I
See also the implementation of some singletons (e.g. gPad, gROOT, gSystem, …) in ROOT.
If the only thing you want is to access your variable “gHistUpdater” from the interpreter, add the following line to your “linkdef.h” file:

#pragma link C++ global gHistUpdater;

I am stupid. No?
Pepe Le Pew.


and you have to first load the library before you can use globals from it. You can also use the singleton approach that Pepe suggests and create a static member function of some class. That allows you to use the class name in a rootmap file (e.g. created with rlibmap) which will trigger automatic loading of your library.

Cheers, Axel.