c++ - Member name lookup rules -
the sec. 10.2 describes fellow member name lookup rules:
10.2/3:
the lookup set f in c, called s(f, c), consists of 2 component sets: declaration set, set of members named f; , subobject set, set of subobjects declarations of these members (possibly including using-declarations) found. in declaration set, using-declarations replaced members designate, , type declarations (including injected-class-names) replaced types designate. s(f, c) calculated follows:
10.2/4:
if c contains declaration of name f, declaration set contains every declaration of f declared in c satisfies requirements of language build in lookup occurs.
consider next 2 examples:
class { void foo(){ a::a; } //s(a, a)={ static const int a; } static const int = 5; } and
class { int b[a::a]; //s(a, a) empty , programme ill-formed static const int = 5; } what actual s(f, c) calculation rules , why?
for these code snippets
class { void foo(){ a::a; } //s(a, a)={ static const int a; } static const int = 5; }; class { int b[a::a]; //s(a, a) empty , programme ill-formed static const int = 5; }; you should consider name lookup described in section 3.4 name lookup of standard. have nil mutual quotes cited. though can show s(f, c) illustration name a::a in first class definition. s( a, ) cosists 1 declaration static const int = 5
take business relationship in sec class definition name a::a not found because has declared before usage.
the other rule used name lookup in fellow member functions. in first class definition name a::a found.
all described in section 3.4 of standard pointed out.
as phrase cited more appropriate illustration example following
struct { void f( int ); }; struct b : { using f; void f( char ); }; in case if name f searched s( f, b ) contain 2 declarations
using f; // or void f( int ); and
void f( char ); c++ class language-lawyer
No comments:
Post a Comment