Scope rules

  • Thread starter n2xssvv g02gfr12930
  • Start date
N

n2xssvv g02gfr12930

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
 
V

Victor Bazarov

n2xssvv said:
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
 
F

Frederick Gotham

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(;;) {}

}
 
N

n2xssvv g02gfr12930

Victor said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top