Thread: Turning a varible into a global.

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005

    Question Turning a varible into a global.

    void make(hwnd HWND) 
    int nVarry = 90;
    void read(hwnd HWND)
    if(nVarry == 90)
    But, sense nVarry was declared inside of a function, a different function cannot read nVarry. So my question is, how can I make a varible (in this case 'nVarry') become a global varible so that it can be read through out the whole app, and not just inside of the brackets that it was created in?

    Thanks in advance, August.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Well, there are usually better methods than creating global variables, but to create one, you simply need to declare it outside the scope of any functions/classes. So, at the top of your file (generally below header includes -- stylistic issue), just declare it: 'int nVarry;'.

    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Registered User
    Join Date
    Nov 2002
    You don't wan tto make it global, why don't yo upass nVarry to each of the functions? Or make those functions members of a class and nVarry a member of it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 12:02 PM
  3. Global objects and exceptions
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 07:37 AM
  4. Global Variables, include files and classes
    By sharpstones in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2005, 10:06 AM
  5. defining and using a global class
    By cjschw in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2004, 09:51 PM