 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Gabriel Zachmann Guest
|
Posted: Mon Dec 15, 2003 5:24 pm Post subject: definition of scope et al. |
|
|
I have a question (apparently, I didn't ask it yet)
concerning the precise defintion of a few terms.
Exactly what are the definitions of the notions "scope", "visibility",
and "namespace", in particular in the context of classes?
Any insights or pointers will be appreciated.
Best regards,
Gabriel.
--
/-------------------------------------------------------------------------
| Quote: | zach (AT) cs (DOT) uni-bonn.de __@/' [email]Gabriel.Zachmann (AT) gmx (DOT) net[/email] |
web.informatik.uni-bonn.de/~zach __@/' www.gabrielzachmann.org |
-------------------------------------------------------------------------/ |
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Mon Dec 15, 2003 10:05 pm Post subject: Re: definition of scope et al. |
|
|
In article <slrnbtpva2.h7r.zach (AT) fuji (DOT) informatik.uni-bonn.de>, Gabriel
Zachmann <zach (AT) cs (DOT) uni-bonn.de> writes
| Quote: | I have a question (apparently, I didn't ask it yet)
concerning the precise defintion of a few terms.
Exactly what are the definitions of the notions "scope", "visibility",
and "namespace", in particular in the context of classes?
|
When you want such definitions first try Bjarne Stroustrup's glossary:
http://www.research.att.com/~bs/glossary.html
Then try Google's glossary resource:
http://labs.google.com/glossary
And as for 'visibility', a declaration of a name is visible if it has
been declared in a scope or an enclosing scope and it hasn't been
hidden:-)
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
or http://www.robinton.demon.co.uk
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
R.F. Pels Guest
|
Posted: Mon Dec 15, 2003 10:13 pm Post subject: Re: definition of scope et al. |
|
|
Gabriel Zachmann wrote:
| Quote: | Exactly what are the definitions of the notions "scope", "visibility",
and "namespace", in particular in the context of classes?
|
I'll have a go.
Scope is the collection of elements that are *accessible* from the current
execution point. For example:
int i = 0;
.... <--- i is in scope here, j is not.
int j = 1;
Visibility is the attribute of all elements in scope. It is possible to
'hide' objects, for example:
int i = 0;
...
if (foo == bar)
{
int i = 42;
... <--- The inner i is visible, the outer i is not,
but both i's are in scope!
Ofcourse, if something is not in scope, it is not visible either.
A namespace is a collection of names. It more or less works the same as
creating a class containing public subclasses, however, there are extra
languange constructs to handle them.
--
Ruurd
..o.
...o
ooo
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Mon Dec 15, 2003 10:16 pm Post subject: Re: definition of scope et al. |
|
|
Gabriel Zachmann wrote:
| Quote: | I have a question (apparently, I didn't ask it yet)
concerning the precise defintion of a few terms.
Exactly what are the definitions of the notions "scope", "visibility",
and "namespace", in particular in the context of classes?
|
"Scope" is used in two different senses:
1. The region of a program in which a particular name-binding
[1] can be used without qualification. This might also be
called its visibility.
2. A region of the program within which names can be bound
independently of bindings in other such regions. The
standard generally calls this a "declarative region".
[1] The association of a name with some entity such as a type
or a set of functions through one or more declarations.
The scope (sense 2) of a class is the body of its definition.
The scope (sense 1) of the name of a class member is
- the part of the body of the class definition following the
first declaration of the name as a member, plus
- the bodies and parameter lists of the class's member
functions, plus
- the initialiser lists of the class's constructors, plus
- all of the above in every derived class
minus the scope of any binding of the same name in another
scope (sense 2).
A "namespace" is a means of restricting the scope of name-
bindings outside of classes and functions. Names declared
outside of any other declaration exist in the global
namespace. Names can be declared in other namespaces using
namespace definitions or qualified names. Example:
int A;
namespace B { int A; } // namespace definition
namespace C { } // namespace definition
int C::A; // qualified name
This declares separate named objects: A, B::A and C::A.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Gabriel Zachmann Guest
|
Posted: Wed Dec 17, 2003 9:56 am Post subject: Re: definition of scope et al. |
|
|
Thanks for your response.
| Quote: | Scope is the collection of elements that are *accessible* from the current
|
i thought, a "scope" is a range of "source code points"?
| Quote: | Ofcourse, if something is not in scope, it is not visible either.
|
see my other response to Francis' reply.
| Quote: | A namespace is a collection of names. It more or less works the same as
|
doesn't a class define a namespace, too?
TIA,
Gab.
--
/-------------------------------------------------------------------------
| Quote: | zach (AT) cs (DOT) uni-bonn.de __@/' [email]Gabriel.Zachmann (AT) gmx (DOT) net[/email] |
web.informatik.uni-bonn.de/~zach __@/' www.gabrielzachmann.org |
-------------------------------------------------------------------------/ |
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Francis Glassborow Guest
|
Posted: Wed Dec 17, 2003 4:51 pm Post subject: Re: definition of scope et al. |
|
|
In article <slrnbtuurt.kjj.zach (AT) fuji (DOT) informatik.uni-bonn.de>, Gabriel
Zachmann <zach (AT) cs (DOT) uni-bonn.de> writes
| Quote: | doesn't a class define a namespace, too?
|
Here we have the problem of keywords that are spelt in ways such that
writing about them without the use of a specific font becomes tortuous.
A class provides a declarative scope.
A namespace provides a declarative scope.
There are many similarities but they are not the same thing. BTW a
function also provides a declarative scope so does a file but people
rarely call those 'name spaces'.
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
or http://www.robinton.demon.co.uk
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|