Global Variables, include files and classes

This is a discussion on Global Variables, include files and classes within the C++ Programming forums, part of the General Programming Boards category; Hello, it seems i've run into some problems using an API that uses global variables. To make things easier to ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    Global Variables, include files and classes

    Hello, it seems i've run into some problems using an API that uses global variables. To make things easier to implement I encapsulated all the code I needed into a class and then in a different program I include the class defintion and make instances of it to interface with the API. Problem is that there is a global variable in the API that it forces me to use and it just doesn't seem to be working.

    How would global variables work in this sense? In my program I include the class definitions at "ctk_RAPIDobj.H" and in the "ctk_RAPIDobj.H" file I include the API's header file "RAPID.H" where the global variable is declared "extern int RAPID_num_contacts."

    Although everything compiles fine it seems that the global variable never changes. I know this has to do something with the setup I'm using because if I just make a program and include "RAPID.H" and run some functions the global variable changes as expected.

    I know this kind of vague but if there is some glaring thing that pops out please let me know. Thank you in advance for your help.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Is it declared like this?
    Code:
    extern int RAPID_num_contacts;
    Or is it initialized?
    Code:
    extern int RAPID_num_contacts= 100;
    Because if it's initialized, the compiler ignores the extern keyword and declares another variable.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  2. Class files including other classes
    By combatdave in forum C++ Programming
    Replies: 7
    Last Post: 11-04-2006, 12:37 AM
  3. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 10:15 AM

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