We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello!
What is the best method to declare some variables global ( more than one .C File should know it ) and still avoid multiple public definitions?
A Global Header File is definitely NOT the key to success ;-)
Thanks for your help!
Most often when I have a global variable, I do like the above. It might be a tick counter or similar that a lot of code would like to be able to access.
When talking about modules, I often have an accessor function (or in case of C++ often a static factory method that returns a single unique object instance). So, the module does not contain any global variables - only static variables (declared with static keyword or in nameless namespace).
However, as Andy notes, alternatives can not be discuessed without first clearly state goals or usability requirements.