Namespaces
Variants
Views
Actions

Talk:cpp/language/unqualified lookup

From cppreference.com
< Talk:cpp‎ | language
Revision as of 01:07, 30 June 2016 by Gubbins (Talk | contribs)

The code snippet: struct V { int v; };
struct A {
        int a;
        static int s;
        enum { e };
};
struct B : A, virtual V { };
struct C : A, virtual V { };
struct D : B, C { };
 
void f(D& pd) {
        ++pd.v; // OK: only one v because only one virtual base subobject
        ++pd.s; // OK: only one static A::s, even though found in B and in C
        int i = pd.e; // OK: only one enumerator A::e, even though found in B and C
        ++pd.a; // error, ambiguous: A::a in B and A::a in C
}

under the section Member function definition of the page [1].

I think there is a mistake on the above snippet. The comment says

// OK: only one static A::s, even though found in B and in C

but It's not ok. You can't change the static variables using the instance. Because static variables are not the member's of instances they are the member's of the class or struct, which retains state information between call that's why they are allocated in .DATA or .BSS

--Appey (talk) 08:32, 28 January 2016 (PST)

In C++ you can. T. Canens (talk) 09:27, 28 January 2016 (PST)

Unqualified lookup of dependent name

I'm confused as to whether there is any such thing as unqualified lookup of a dependent name. Is there an obvious example?