member name lookup

F

Fraser Ross

10.2/2 of the C++ standard says this:

"The following steps define the result of name lookup in a class
scope, C. First, every declaration for the name in the class and in
each of its base class sub-objects is considered. A member name f in
one subobject B hides a member name f in a sub-object A if A is a base
class sub-object of B. Any declarations that are so hidden are
eliminated from consideration. Each of these declarations that was
introduced by a using-declaration is considered to be from each sub-
object of C that is of the type containing the declaration designated
by the using-declaration. If the resulting set of declarations are not
all from sub-objects of the same type, or the set has a nonstatic
member and includes members from distinct sub-objects, there is an
ambiguity and the program is ill-formed...."


I don't understand the sentence beginning with the word Each. Is it
wrong?

Fraser.
 
J

jalina

Fraser Ross a écrit :
10.2/2 of the C++ standard says this:

"The following steps define the result of name lookup in a class
scope, C. First, every declaration for the name in the class and in
each of its base class sub-objects is considered. A member name f in
one subobject B hides a member name f in a sub-object A if A is a base
class sub-object of B. Any declarations that are so hidden are
eliminated from consideration. Each of these declarations that was
introduced by a using-declaration is considered to be from each sub-
object of C that is of the type containing the declaration designated
by the using-declaration. If the resulting set of declarations are not
all from sub-objects of the same type, or the set has a nonstatic
member and includes members from distinct sub-objects, there is an
ambiguity and the program is ill-formed...."


I don't understand the sentence beginning with the word Each. Is it
wrong?

You lucky if this is the only sentence you don't understand in the C++
standard.
 
V

Victor Bazarov

Fraser said:
10.2/2 of the C++ standard says this:

"The following steps define the result of name lookup in a class
scope, C. First, every declaration for the name in the class and in
each of its base class sub-objects is considered. A member name f in
one subobject B hides a member name f in a sub-object A if A is a base
class sub-object of B. Any declarations that are so hidden are
eliminated from consideration. Each of these declarations that was
introduced by a using-declaration is considered to be from each sub-
object of C that is of the type containing the declaration designated
by the using-declaration. If the resulting set of declarations are not
all from sub-objects of the same type, or the set has a nonstatic
member and includes members from distinct sub-objects, there is an
ambiguity and the program is ill-formed...."


I don't understand the sentence beginning with the word Each. Is it
wrong?

struct A {
void f();
};

struct B : A {
void f(int);
};

struct C : B {
void f(double);
using B::f;
};

struct CC : B {
void f(double);
using A::f;
};

struct D : B {
void f(char*);
};

int main() {
C c;
CC cc;
D d;
c.foo(2); // case 1
cc.foo(); // case 2
d.foo(); // case 3
d.foo(2); // case 4
}

The lookup in case 1 and case 2 should consider 'foo' introduced into
the scope of 'C' and 'CC', respectively, the former from 'B' and the
latter from 'A'. That's what the sentence seems to say (to me at least).

V
 

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