Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!newcastle.ac.uk!cabernet!ngdp From: Graham.Parrington@newcastle.ac.uk (Graham D. Parrington) Newsgroups: comp.lang.c++ Subject: Overloaded Function Ambiguity Resolution Problems Message-ID: <1991Feb27.084909.5063@newcastle.ac.uk> Date: 27 Feb 91 08:49:09 GMT Sender: news@newcastle.ac.uk Organization: University of Newcastle upon Tyne, UK, NE1 7RU Lines: 53 Consider the following code fragment: #include "stream.h" class Base { public: Base() { cout << "Base::Base()\n"; } Base(char *) { cout << "Base::Base(char *)\n"; } void func(char*) { cout << "Base::func(char *)\n"; } }; class Derived:public Base { public: Derived() { cout << "Derived::Derived()\n"; } void func(const Base&){ cout << "Derived::func(const Base&)\n"; } }; main() { Derived *d = new Derived(); d->func("hello"); } What should it output? Cfront 2.1 (<>) gives: Base::Base() Derived::Derived() Base::Base(char *) Derived::func(const Base&) while g++ (version 1.39.0 beta (based on GCC 1.39)) gives: Base::Base() Derived::Derived() Base::func(char *) That is, g++ considers Base::func(char*) to be the correct match to the call while cfront prefers to construct a Base first and then use Derived::func(Base) My reading of the ARM pp318-> makes me believe that g++ is correct in this case since there is an exact match on argument type (rule 1), whereas cfront appears to apply rule 4 (user defined conversion). I suspect the differences lie in search strategies in the two compilers, that is, g++ applies the rules in order over the entire hierachy, while cfront applies the rules first on the current class and then on its parents etc. What do other compilers make of this example (Zortech, Glockenspiel, etc), and more importantly which is the CORRECT behaviour?? EMAIL = Graham.Parrington@newcastle.ac.uk POST = Computing Laboratory, The University, Newcastle upon Tyne, UK NE1 7RU VOICE = +44 91 222 8067 FAX = +44-91-222-8232