Thread: global variables

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    13

    global / static variables

    hi, this should be an easy one, i just havent dealt much with global variables.

    i have an unmanaged c++ project set up with many different classes. Each class has its own .h and .cpp set up correctly. They're included in a standard library that each cpp references. All of this works.

    There is a main cpp file which also references the standard library. all of its functions are global, and can be accessed from any other class or file. Should its variables, declared outside of functions then also be global, and available from any class? They're not. Other classes can't find these variables. When added to the standard library, they get an error because they are created about 20 different times (once per .cpp file that includes the library) despite the "#pragma once" that i have.

    I need these variables to be available everywhere. Am i just missing some syntax? or would a namespace be my solution. I'd like to avoid the latter if at all possible.

    thanks in advance.
    Last edited by shadovv; 10-23-2005 at 11:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  2. scope of global variables
    By laertius in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2006, 01:59 AM
  3. global variables - okay sometimes...?
    By MadHatter in forum C++ Programming
    Replies: 21
    Last Post: 01-21-2003, 04:23 PM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 10:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM