Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Scope rules

Reply
Thread Tools

Scope rules

 
 
n2xssvv g02gfr12930
Guest
Posts: n/a
 
      07-20-2006

Although I rarely if ever have a problem with scope, I was wondering
whether anybody knows of good reference, (book, web page, etc), that
covers scope rules. Hopefully this will be helpful to others.

JB
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-20-2006
n2xssvv g02gfr12930 wrote:
> Although I rarely if ever have a problem with scope, I was wondering
> whether anybody knows of good reference, (book, web page, etc), that
> covers scope rules. Hopefully this will be helpful to others.


You mean like "Always keep the scope of the name as tight as possible"?
Or do you mean like "overloading only relates to functions in the same
scope" and the related "derived class scope is tighter than the base
class scope (and included in it)"?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Frederick Gotham
Guest
Posts: n/a
 
      07-20-2006
n2xssvv g02gfr12930 posted:


> Although I rarely if ever have a problem with scope, I was wondering
> whether anybody knows of good reference, (book, web page, etc), that
> covers scope rules. Hopefully this will be helpful to others.



A rule of thumb would be:

An object exists from the point of its definition, until the next
closing brace. (Unless it's static of course).


If you define an object within a "for" loop as follows:

for(int i; {}


Then its scope is as if you wrote:

{
int i;

for(; {}

}


--

Frederick Gotham
 
Reply With Quote
 
n2xssvv g02gfr12930
Guest
Posts: n/a
 
      07-20-2006
Victor Bazarov wrote:
>
> You mean like "Always keep the scope of the name as tight as possible"?
> Or do you mean like "overloading only relates to functions in the same
> scope" and the related "derived class scope is tighter than the base
> class scope (and included in it)"?
>
> V


All of those points would be nice, with examples demonstrating the how
and the why. Perhaps I should create some web pages on scope covering
class, namespace, code scope, and any others you'd like to suggest.
Thanks for your response, and no doubt you could think of countless
examples.

JB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: QUERY: 'On Error Resume Next' scope rules Kevin Spencer ASP .Net 0 06-17-2006 03:33 PM
Scope Rules fctk C Programming 3 04-18-2006 11:03 AM
rules for Cisco PIX 525 firewall rules KAS Cisco 2 10-02-2005 07:12 PM
Special scope rules for static operators? =?ISO-8859-1?Q?=22J=2EJ=2EGarc=EDa=22?= C++ 4 05-29-2005 05:42 PM
scope rules in nested functions Andrew Collier Python 0 01-29-2005 10:07 PM



Advertisments