Thread View: gnu.g++.bug
1 messages
1 total messages
Started by "Douglas C. Schmidt"
Sun, 01 Jan 1989 21:07
g++ allows ambigous member function overloading with default parameters
Author: "Douglas C. Schmidt"
Date: Sun, 01 Jan 1989 21:07
Date: Sun, 01 Jan 1989 21:07
43 lines
1489 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads