Article View: alt.comp.lang.learn.c-c++
Article #478Re: Sharing a variable through my project in BC++ 5.02
From: Trenton D. Adams
Date: Mon, 02 Feb 1998 00:00
Date: Mon, 02 Feb 1998 00:00
99 lines
4331 bytes
4331 bytes
Thanks for your reply. Also, it isn't a compiler specific request. I was just asking how I share variables through multiple cpp files. I figured it out though. I delcared it in my main application cpp file, then I used extern variable to access it in all my other ones. Thanks again for the reply though. Jim Fischer wrote: > > -----Original Message----- > From: Trenton D. Adams <adamst@telusplanet.net> > Newsgroups: > alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++ > Date: Sunday, February 01, 1998 9:06 PM > Subject: Sharing a variable through my project in BC++ 5.02 > > >I used AppExpert to create a basic application. I then modified, and > >added things that I wanted. I have gotten all of my Dialogs and > >everything working. > > > >My question now is this. How the heck do I make a variable that will > >keep it's value through my whole program? I thought this would be very > >simple to figure out but nothing seems to work. Here is an example of > >what I want. My Application object is in a Header, and a CPP file. My > >Dialog boxes are all in their own Header, and cpp files also. How do I > >get a variable that will be shared between all of them? > > [Side note] > Compiler-specific messages should really be posted to the newsgroup that is > dedicated to that compiler product, not to comp.lang.c++ [ref: section 5.8 > of the FAQ for the comp.lang.c++ newsgroup]. > [/Side note] > > I don't know how Borland's "AppExpert" works, so I can't tell you how to use > that feature to do what you need to do. > > What I can do is describe how this is done by everyone else in the C++ world > [i.e., everyone else who does not use Borland's AppExpert]. > > 1) In one of your C++ source code files, define the global variable: > > --- begin some.cpp --- > > #include "some.h" > > /*...*/ > > // Global variable definition > int g_Handle ; > > /*...*/ > --- end some.cpp --- > > 2) Write an "extern" declaration for this variable in a header file. For > example: > > --- begin some.h --- > #ifndef SOME_H > #define SOME_H > > /*...*/ > > // Declare the existance of the global variable 'g_Handle' > extern int g_Handle ; > > #endif // SOME_H > --- end some.h --- > > 3) #include this header file into every translation unit in which the global > variable 'g_Handle' is used. > > Jim Fischer > Computer Engineering, Senior > Cal Poly, SLO > > P.S. > > FWIW, Borland has their own Internet news server on which you can > find peer-to-peer newsgroups that are dedicated to their software > products. The Internet address of Borland's NNTP news server is, > > forums.borland.com > > On this news server, the newsgroups that pertain to Borland's C++ > compiler products [and OWL] all start with, > > borland.public.cpp.<specific group> > borland.public.cppbuilder.<specific group> > > There are also a large number of Windows programming newsgroups on > Borland's news server as well. > > [Note: Borland's newsgroups are not available via your ISP's Usenet > news server. You must configure your news reader software to connect > directly to Borland's NNTP news server via the Internet. Most of the > current news reader applications [e.g., Netscape Navigator, MS Outlook > Express [p/o IE 4.0x] have the ability to connect via the Internet to > multiple NNTP news servers, including "locally owned" servers such as > Borland's.]
Technical Details
Message-ID:
<34D63CDA.28306AA6@telusplanet.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01b501bd2f9e$ad5f3cc0$89644181@jfischer.harp.calpoly.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,cc5639ecc55682f1 X-Google-Attributes: gidf8d38,public X-Google-Thread: 114592,cc5639ecc55682f1 X-Google-Attributes: gid114592,public X-Google-Thread: 109fba,cc5639ecc55682f1 X-Google-Attributes: gid109fba,public From: "Trenton D. Adams" <adamst@telusplanet.net> Subject: Re: Sharing a variable through my project in BC++ 5.02 Date: 1998/02/02 Message-ID: <34D63CDA.28306AA6@telusplanet.net> X-Deja-AN: 321469055 Content-Transfer-Encoding: 7bit References: <01b501bd2f9e$ad5f3cc0$89644181@jfischer.harp.calpoly.edu> To: Jim Fischer <jfischer@polymail.calpoly.edu> Content-Type: text/plain; charset=us-ascii Organization: TELUS Communications Inc. Mime-Version: 1.0 Newsgroups: alt.comp.lang.learn.c-c++,borland.public.cpp.language,comp.lang.c++