Hello.
I have declared a boolean global variable within a header file.
Now, I want to change value of global variable within a function in another file such that it is globally changed.
Thanks in advance for your answers.
Regards,
Sunny.
Hello.
I have declared a boolean global variable within a header file.
Now, I want to change value of global variable within a function in another file such that it is globally changed.
Thanks in advance for your answers.
Regards,
Sunny.
If you want to go that route, you really should declare the variable as being extern in the header file, and redeclare it (without the extern) in the appropriate .cpp file that implements that header. After you do that, you will be able to alter the variable elsewhere if you include that header file.
A more appropriate way of handling this would be to disallow other parts of your program from seeing the boolean variable. What they should be able to see are two functions, one that sets the variable and one that gets the value of the variable. If you need to add debugging information later on, you can control how other parts of your program interface with the variable at those two places instead of tracking all throughout your program for such changes.