473,805 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scope rules


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
Jul 20 '06 #1
3 2139
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 "overloadin g 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
Jul 20 '06 #2
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
Jul 20 '06 #3
Victor Bazarov wrote:
>
You mean like "Always keep the scope of the name as tight as possible"?
Or do you mean like "overloadin g 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
Jul 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

33
3560
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
7
2196
by: Michael G | last post by:
I am a little surprised that the following that $x is visible outside of the scope in which it is (?)defined(?) (not sure if that is the correct term here). I am trying to find where in the php docs that this is discussed. Haven't found anything yet. Any help appreciated. I am also assuming that the following scoping rule holds for other constructs
8
3393
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an actual program. To me "scope" of the name of a function or object are the general rules for the areas of a program that can through a declaration, have "visibility."
3
4143
by: fctk | last post by:
are the following rules correct in C89/C90? ---- SCOPE RULES 1) the scope of an identifier declared inside a block is the block in which it is declared; 2) when you have nested blocks (extern block and internal block), an identifier declared in the external block is known also in the internal block, while an identifier declared in the internal block is not known
39
3204
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the function changes the state of the object, it ought to be a member of that object." Reference Accelerated C++, A. Koenig, page 159.
2
2294
by: James Brown | last post by:
All, Could anyone explain why the following is an error: void foo( struct FOO { int x; } f1 ) { } int main()
5
2037
by: Steven T. Hatton | last post by:
If find the following excerpt from the Standard a bit confusing: <quote> 3.3.6 - Class scope -1- The following rules describe the scope of names declared in classes. 1) The potential scope of a name declared in a class consists not only of the declarative region following the name's declarator, but also of all function bodies, default arguments, and constructor ctor-initializers in that class (including such things in nested classes).
7
5785
by: Johannes Bauer | last post by:
Hello Group, please consider the following code #include <vector> #include <iostream> #define USE_CONST #define USE_STRING
1
2356
by: Tim Haughton | last post by:
Firstly, if there's a better newsgroup to ask this on, feel free to redirect me. I have these requirements of WDS for a project: 1) I need to be able to add a new location to the user scope rules for WDS so that it indexes an application specific folder. This folder, at the moment, contains only text files. 2) This folder *should not* be included in any of Vista's searches from the
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.