Re: Which scope is searcheg first ?
From: Jerry Coffin (jcoffin_at_taeus.com)
Date: 06/16/04
- Next message: Mark A. Gibbs: "Re: validation"
- Previous message: jianjia: "Re: Wrong Result in finding GCM"
- In reply to: Razvan: "Which scope is searcheg first ?"
- Next in thread: Razvan: "Re: Which scope is searcheg first ?"
- Reply: Razvan: "Re: Which scope is searcheg first ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 15 Jun 2004 19:56:19 -0700
mihai11@mailcity.com (Razvan) wrote in message news:<15f19d61.0406151238.1bdf0f17@posting.google.com>...
[ ... ]
> I took a C++ test and I found the following question:
>
>
>
> Q. Inside a class member function definition, which scope is searched
> first when an unqualified variable is accessed?
>
> 1.Class static data
> 2.Global namespace data
> 3.Function local data
> 4.Current namespace data
> 5.Class member data
Technically, none of the above. _Block_ local data is searched first.
Just for example:
int func() {
int a; // function local data
if ( something) {
float a; // block local data
a = 1; // unqualified variable access.
In this case, the function-local data is NOT used -- the block-local
data is what is accessed. For the most part, the rule is pretty
simple though: searching starts at the most local scope and progresses
outward to the least local scope.
There are exceptions to this though -- for an obvious one, a using
declaration can "teleport" the names from some namespace into the
local scope. Templates also have some oddities because searching
happens both in the scope where the template is instantiated AND the
scope where it is defined (I'm simplifying a bit, but hopefully I'm
portraying the basic idea). In the usual case, that's pretty
straightforward, but when/if you export a template, it can get
substantially more complex.
--
Later,
Jerry.
The universe is a figment of its own imagination.
- Next message: Mark A. Gibbs: "Re: validation"
- Previous message: jianjia: "Re: Wrong Result in finding GCM"
- In reply to: Razvan: "Which scope is searcheg first ?"
- Next in thread: Razvan: "Re: Which scope is searcheg first ?"
- Reply: Razvan: "Re: Which scope is searcheg first ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|