1
0

support.cpp 809 B

12345678910111213141516171819202122232425262728
  1. // support.cpp -- use external variable
  2. // compile with external.cpp
  3. #include <iostream>
  4. extern double warming; // use warming from another file
  5. // function prototypes
  6. void update(double dt);
  7. void local();
  8. using std::cout;
  9. void update(double dt) // modifies global variable
  10. {
  11. extern double warming; // optional redeclaration
  12. warming += dt; // uses global warming
  13. cout << "Updating global warming to " << warming;
  14. cout << " degrees.\n";
  15. }
  16. void local() // uses local variable
  17. {
  18. double warming = 0.8; // new variable hides external one
  19. cout << "Local warming = " << warming << " degrees.\n";
  20. // Access global variable with the
  21. // scope resolution operator
  22. cout << "But global warming = " << ::warming;
  23. cout << " degrees.\n";
  24. }