Hi!

Here is a real C++ noob question. I want to define a global variable that is changable with a slider and accessible to all objects in my project. I tried it like this:

Qt Code:
  1. #ifndef CONSTANTS_H
  2. #define CONSTANTS_H
  3.  
  4. #define PI 3.14159265358979323846
  5. #define G 9.81
  6. #define FPS 90
  7.  
  8. extern double GAMMA;
  9. double GAMMA = 0.01;
  10.  
  11. #endif // CONSTANTS_H
To copy to clipboard, switch view to plain text mode 

Until now I only had the #defined globals and it worked great by including constants.h everywhere I needed them. Now I have a new parameter GAMMA, which is not only global, but also needs to be changed from time to time.

Well, this doesn't work, otherwise I wouldn't be asking. I get a compile error:

debug/passivewalker.o: In function `ZN5QLineC1Eiiii':
c:/Qt/4.4.3/include/QtGui/../../src/gui/painting/qpainter.h.data+0x0): multiple definition of `GAMMA'
debug/stickman.o:C:/Qt/2009.03/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/locale_facets.tcc:2497: first defined here
collect2: ld returned 1 exit status
It's not that the name GAMMA is already taken. I tried renaming it to something really special and it didn't help. I would like to keep all globals, constant or not, in one header file. What am I doing wrong?

Thanks
Cruz