variables scope

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 159
Reputation: cam875 is an unknown quantity at this point 
Solved Threads: 3
cam875 cam875 is online now Online
Junior Poster

variables scope

 
0
  #1
Jan 1st, 2009
how do i make it so that functions and procedures that are located in other files in the include statement have access to the global variables within main.cpp, thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: variables scope

 
0
  #2
Jan 1st, 2009
Originally Posted by cam875 View Post
how do i make it so that functions and procedures that are located in other files in the include statement have access to the global variables within main.cpp, thanks in advance.
As usually:
main.cpp:
  1. ...
  2. bool troublesWanted = true;
  3. bool IlikeBadDesign = true;
  4. ...
  5. int main()
  6. { ... }
  7. void Nil() {}
globals.h:
  1. #ifndef GLOBALS_H
  2. #define GLOBALS_H
  3. extern bool troublesWanted;
  4. extern bool IlikeBadDesign;
  5. void Nil();
  6. #endif
another.cpp:
  1. ...
  2. #include "globals.h"
  3. void Void()
  4. {
  5. if (!troublesWanted)
  6. IlikeBadDesign = false;
  7. else
  8. Nil();
  9. }
Last edited by ArkM; Jan 1st, 2009 at 7:46 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 383 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC