[C++] Errors when gcc chooses operators
Philipp Thomas
pthomas@suse.de
Tue Apr 16 14:43:00 GMT 2002
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
More information about the Gcc-bugs
mailing list