0

Say I have a source file called main.cpp. Within this source file, I declare some variables outside the main() function. Then inside the main() function I call a class member function (which is properly declared and implemented in other .h and .cpp files) to assigns a value to one of the variables defined as outlined above (i.e. outside the main() function in main.cpp). When I do this it gives a "variable not defined in scope error". Does anyone know how I can solve this?

user2225868
  • 33
  • 2
  • 7
  • use `extern T name` to declare a variable of type `T` that is located in another compilation unit. – Mats Petersson Jul 22 '13 at 23:04
  • possible duplicate of [static and extern global variables in C and C++](http://stackoverflow.com/questions/11055802/static-and-extern-global-variables-in-c-and-c) – Borgleader Jul 22 '13 at 23:04
  • 5
    Please just **don't use global variables.** No. Full stop. It's not good in C either, but in C++, it's even worse. –  Jul 22 '13 at 23:08

0 Answers0