When I build this code, the compiler gives me "undefined reference to 'Index'" error. I tried all different combinations of defining as various ways.When I change the declaration of RefrigerantIndex in Data.h from externint Index; to staticint Index;, it compiles and builds well. I dont know which is the right way to do.
I would appreciate your help in getting this matter resolved. I can keep this as static and go on for now, but I would like to build the code in the best possible way byt understanding what I am writing. In addition to help, if any one can suggest excellent references (video tutorials) to understand various concepts that would be very helpful.
At line 23 you're saying that index had global scope. e.g. ::Index
At line 56, index has local scope. e.g. main::Index.
To the lnker, these are two different variables.
Move line 56 to global scope (line 53) and you should be fine.
I now see what the scope of the variable is. Do you have any recommendation on the advantages and disadvantages on this kind of usage. I read that use of global variables is not a really good way to program in C++.
If this is not the best way to program the above task, it would be great if you could (if you have time) show us how could this program be made better.
You're correct that it's best to avoid global variables.
Looking more closely at you program, I don't see that you have any need for the global instance of Index. I would just eliminate the global instance (and it's extern) and leave the local instance of inside main.