This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]