I have declared global variables in the main file. Then in other files where I need it, I refer to these variables with extern in the .cpp.
But I also need to refer to some of these global variables in some inline functions, and thus to refer to these variables with extern in the .h. But with #include directives, it looks like a big mess. Besides, some types are not yet defined.
So my question is : what is the best method or paradigm to use global variables in inline functions ?
Thanks Moschops. But I would like to avoid having to rewrite all this code. I miss inline function body shall be in header files. My opinion is that it is a bad design of the c++ compiler..... To what you will repeat that the bad design is to use global variables.
You do tell me what not to do, but not what to do. Shall I put everything in classes and use friend ? What is the good way ?
Building target: test
Invoking: GCC C++ Linker
g++ -L/usr/lib64 -o"test" ./src/Global.o ./src/test.o
./src/test.o: In function `main':
test.cpp:(.text+0x1b58): undefined reference to `token'
collect2: ld has returned 1 code running status
make: *** [test] Error 1
If I comment : #ifndef GLOBAL in Global.h, then it works.
Could someone explain that to me please ? Why does it fail with it ?