c++ - Unrecognized inherited function -
running c++ source on visual c++ 2010:
class b{ public: virtual void f(int a){} virtual void f(){} }; class a:public b{ public: virtual void f(int a){} }; int main(){ a; a.f(); homecoming 0; } leads next error:
intellisense: few arguments in function call
in other words, seems void f() didn't inherited?
what problem?
it seems void f() didn't inherited?
the name f in class shadows name f in b. can still access foo() b way
a a; a.b::f(); other alternative redeclare function foo of b in scope of a:
class : public b{ public: virtual void f(int a) {} using b::foo; }; c++ standard n3337 § 10.2 fellow member name lookup
1) fellow member name lookup determines meaning of name (id-expression) in class scope (3.3.7). name lookup can result in ambiguity, in case programme ill-formed. id-expression, name lookup begins in class scope of this; qualified-id, name lookup begins in scope of nested- name-specifier. name lookup takes place before access command (3.4, clause 11).
2) next steps define result of name lookup fellow member name f in class scope c.
3) 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:
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. [ note: looking name in elaborated-type-specifier (3.4.4) or base-specifier (clause 10), instance, ignores non- type declarations, while looking name in nested-name-specifier (3.4.3) ignores function, variable, , enumerator declarations. example, looking name in using-declaration (7.3.3) includes declaration of class or enumeration ordinarily hidden declaration of name in same scope. — end note ] if resulting declaration set not empty, subobject set contains c itself, , calculation complete.
5) otherwise (i.e., c not contain declaration of f or resulting declaration set empty), s(f, c) empty. if c has base of operations classes, calculate lookup set f in each direct base of operations class subobject bi , , merge each such lookup set s(f, bi ) in turn s(f, c).
c++ inheritance
No comments:
Post a Comment