Path: utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.edu From: schmidt%crimee.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt") Newsgroups: gnu.g++.bug Subject: g++ allows ambigous member function overloading with default parameters Message-ID: <8901011314.aa03646@PARIS.ICS.UCI.EDU> Date: 1 Jan 89 21:07:13 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 43 Hi, The following C++ code demonstrates a problem with g++ 1.32. ---------------------------------------- // overloaded functions are ambiguous. #include class Foo { public: double i ( double = 10 ) { cout << "hello, this is wrong!\n"; return ( 10.0 ); } int i ( int = 10 ) { cout << "goodbye\n"; return ( 1 ); } }; main ( int, char *[ ] ) { Foo Bar; int i = Bar.i(); // ambiguous call. } ---------------------------------------- g++ compiles this without complaint, and then calls the *first* of the two overloaded member functions ( i.e., it seems to follow the rule that the first member function whose signature matches the call should be used. ). This seems rather arbitrary, and a warning message should probably be given. AT&T cfront 1.2.1. also gets this wrong, but at least it gives a warning message to the effect that int i = Bar.i() is attempting to assign a double to an int. Doug