This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[C++] Errors when gcc chooses operators
- From: Philipp Thomas <pthomas at suse dot de>
- To: gcc-bugs at gcc dot gnu dot org
- Cc: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: Tue, 16 Apr 2002 20:47:11 +0200
- Subject: [C++] Errors when gcc chooses operators
class foo
{
public:
int &operator[] (int x);
int operator[] (int x) const;
double operator[] (double x) const;
};
void bar()
{
foo arr;
arr[2] = 5; // OK
int i = arr[10]; // OK
double x = arr[0.5]; // ERROR
}
Will get you:
c++_bug.cc: In function `void bar()':
c++_bug.cc:15: choosing `double foo::operator[](double) const' over `int& foo::operator[](int)'
c++_bug.cc:15: because worst conversion for the former is better than worst conversion for the latter
c++_bug.cc:15: choosing `double foo::operator[](double) const' over `int& foo::operator[](int)'
c++_bug.cc:15: because worst conversion for the former is better than worst conversion for the latter
First question is, why I'm getting these and the second, why gcc flags these
as errors.
--
Philipp Thomas <pthomas@suse.de>
SuSE Linux AG, Deutscherrnstr. 15-19, D-90429 Nuremberg, Germany