Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!world!wmm From: wmm@world.std.com (William M Miller) Newsgroups: comp.lang.c++ Subject: Re: Overloaded Function Ambiguity Resolution Problems Message-ID: <1991Feb27.204841.14690@world.std.com> Date: 27 Feb 91 20:48:41 GMT References: <1991Feb27.084909.5063@newcastle.ac.uk> Organization: The World Public Access UNIX, Brookline, MA Lines: 34 Graham.Parrington@newcastle.ac.uk (Graham D. Parrington) writes: > class Base > { > public: > Base(char *) { cout << "Base::Base(char *)\n"; } > void func(char*) { cout << "Base::func(char *)\n"; } > }; > > class Derived:public Base > { > public: > void func(const Base&){ cout << "Derived::func(const Base&)\n"; } > > }; > > main() > { > Derived *d = new Derived(); > > d->func("hello"); > } > > What should it output? The cfront output is correct, G++ is wrong. See E&S section 13.1, page 310: "Two function declarations of the same name refer to the same function if they are in the same scope and have identical argument types (section 13). A function member of a derived class is NOT in the same scope as a function member of the same name in a base class." In this example, d->func("hello") can only refer to Derived::func(const Base&), since Base::func(char*) is hidden in the scope of Derived. -- William M. Miller, Glockenspiel, Ltd. wmm@world.std.com