Creating Global Variables For ALL Files. (C++)
Ether my brain is shutting down on me for not sleeping right now, but my mind is blank and I did some searching, but I want to create a variable that is defined and is available in each file to change the values for one file to another.
Example if I had a bool called talk that I defined in one file and wanted to change the value in different CPP file or header how can I do it for all files?
you can use keyword extern as in:
=== main.cpp ===
float foo = 10;
=== other.cpp ===
extern float foo;
foo = 20;
=== main.cpp ===
float foo = 10;
=== other.cpp ===
extern float foo;
foo = 20;
Quote:Original post by ajm113
Ether my brain is shutting down on me for not sleeping right now
If you are sleep deprived and can't figure something out, it is nearly always correct to sleep and worry about it later.
Quote:, but my mind is blank and I did some searching, but I want to create a variable that is defined and is available in each file to change the values for one file to another.
Why do you think you want to do this?
Thanks, got it going!
@Zahlman
Because I want to disable model rotation to allow the camera to rotate with out the model moving with it.
@Zahlman
Because I want to disable model rotation to allow the camera to rotate with out the model moving with it.
Argh. This is not a good enough reason to warrant globals IMHO. Think about if your code becomes more complex -- you'll sometimes want to look where you declared something and finding globals is such a pain :( (especially if you didn't write the code in the first place).
Just my two cents.
~Shiny
Just my two cents.
~Shiny
Quote:Original post by ajm113
Thanks, got it going!
@Zahlman
Because I want to disable model rotation to allow the camera to rotate with out the model moving with it.
So, you have one module that represents the model, and offers an interface for rotating it, and another module that decides when/whether to rotate the model (and/or camera), and which can be told "never rotate the model" with a function, not a "published" global variable. Even if it needs a global for the implementation to work, you can put a saner interface on it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement