General wondering

This is a discussion on General wondering within the C++ Programming forums, part of the General Programming Boards category; My program uses multiple source files wich uses some global variables. I made a header file called globals.h and included ...

  1. #1
    Unregistered
    Guest

    Question General wondering

    My program uses multiple source files wich uses some global variables. I made a header file called globals.h and included it in every source file. I used #ifndef .. #define ... etc.
    When I try to run my program, it says that the variables are already declared in the other source file and gives an error, but my program still runs fine!!

    So how do I get around those errors, cause a lot of errors in a code cant be right

  2. #2
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    Try to declare the global variables in globals.h as follows:

    extern DWORD g_dwVar1;
    extern UCHAR g_ucVar2;

    Then, in ONE cpp file that includes globals.h (eg. globals.cpp) type:

    DWORD g_dwVar1(0);
    UCHAR g_ucVar2(0);

    Let me know if it works!
    Greetings.

  3. #3
    Unregistered
    Guest

    Post

    It worked, but its not what I wanted
    globals.h is so that i would have to write all variables once.
    Still THX though!

  4. #4
    Registered User Ward's Avatar
    Join Date
    Sep 2001
    Location
    Belgium
    Posts
    39
    ...You can't always get what you want...
    Greetings.

  5. #5
    Unregistered
    Guest

    Unhappy


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. General Guidelines on Preventing Header File collision
    By stanlvw in forum C++ Programming
    Replies: 12
    Last Post: 07-05-2008, 04:02 AM
  2. General Steps a game should have
    By Atolar in forum Game Programming
    Replies: 10
    Last Post: 04-22-2006, 09:35 AM
  3. Splitting BST General
    By cpp_is_fun in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2005, 01:02 AM
  4. general function calling
    By techrolla in forum C Programming
    Replies: 4
    Last Post: 01-09-2004, 10:50 AM
  5. General Protection Exception
    By s9uare in forum C++ Programming
    Replies: 1
    Last Post: 11-02-2002, 09:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21