🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1587

g++ allows ambigous member function overloading with default parameters

#1587
From: "Douglas C. Schmidt"
Date: Sun, 01 Jan 1989 21:07
43 lines
1489 bytes
Hi,

   The following C++ code demonstrates a problem with g++ 1.32.

----------------------------------------
// overloaded functions are ambiguous.

#include <stream.h>

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
Technical Details
Message-ID: <8901011314.aa03646@PARIS.ICS.UCI.EDU>
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%crimee.ics.uci.edu

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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