Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11675
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Can I avoid using a global?! |
| Date | 2011-11-22 17:15 +1300 |
| Message-ID | <9j0lvhFr4nU3@mid.individual.net> (permalink) |
| References | <255733fa-a403-42f4-9f00-fb14bea9dec4@z22g2000prd.googlegroups.com> <9j099tFr4nU2@mid.individual.net> <75b5ff25-fbbd-49d9-b074-b6b6f9e53c45@v31g2000prg.googlegroups.com> |
On 11/22/11 05:08 PM, mike3 wrote:
> On Nov 21, 5:39 pm, Ian Collins<ian-n...@hotmail.com> wrote:
>> On 11/22/11 01:07 PM, mike3 wrote:
>>
>>> Hi.
>>
>>> I've got this problem. I was building a game in C++, and ran into
>>> this, which is causing me some trouble. I was wondering if I could
>>> avoid using a global here since I've heard that globals are "bad".
>>
>> Global variables are best avoided.
>>
>>> I've also heard global _functions_ are bad too. If that's the case,
>>
>> It isn't, it's nonsense!
>
> Hmm. Now I've got another question. In this program, I have a number
> of
> objects that represent various parts of the screen to draw in
> ("windows").
> These are "global" to the source code file that handles the display,
> but
> are not accessed anywhere outside that -- or at least not visibly,
> since
> there are functions that can be called from outside that use them. Is
> this
> global bad? If so, what can be done to replace it?
It would be tidier to put them in the unnamed namespace. That way they
really will only be visible in the source file where they are defined.
> Namely, I've got some stuff like:
>
> --- Code ---
namespace {
> DisplayWindow *msgWnd, *gameWnd, *statsWnd;
}
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-21 16:07 -0800
Re: Can I avoid using a global?! Ian Collins <ian-news@hotmail.com> - 2011-11-22 13:39 +1300
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-21 20:08 -0800
Re: Can I avoid using a global?! Ian Collins <ian-news@hotmail.com> - 2011-11-22 17:15 +1300
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-21 23:18 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-21 23:36 -0800
Re: Can I avoid using a global?! "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-11-22 09:09 +0100
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 02:02 -0800
Re: Can I avoid using a global?! Stuart Redmann <DerTopper@web.de> - 2011-11-22 05:02 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 12:43 -0800
Re: Can I avoid using a global?! Stuart Redmann <DerTopper@web.de> - 2011-11-22 23:04 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-23 13:27 -0800
Re: Can I avoid using a global?! Stuart Redmann <DerTopper@web.de> - 2011-11-23 22:40 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-22 06:08 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 12:32 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-22 23:50 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 12:46 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-23 00:02 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-23 13:25 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-24 05:45 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-24 19:44 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-22 01:36 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 02:09 -0800
Re: Can I avoid using a global?! Goran <goran.pusic@gmail.com> - 2011-11-22 03:03 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 12:48 -0800
Re: Can I avoid using a global?! ralph <nt_consulting64@yahoo.net> - 2011-11-21 22:59 -0600
Re: Can I avoid using a global?! Juha Nieminen <nospam@thanks.invalid> - 2011-11-22 07:53 +0000
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 02:05 -0800
Re: Can I avoid using a global?! Mielke <smielke@webpartner.com.br> - 2011-11-22 07:35 -0800
Re: Can I avoid using a global?! mike3 <mike4ty4@yahoo.com> - 2011-11-22 12:34 -0800
Re: Can I avoid using a global?! Krice <paulkp@mbnet.fi> - 2011-11-23 00:42 -0800
csiph-web