From: Arno on 28 Jan 2010 08:19 Hello, is this expected behavior or a bug in Visual C++ 9? enum E { e1 }; bool operator<=( E, E ) { return false; } void main() { E e1; e1<=e1; } leads to compiler error test6.cpp(10): could be 'bool operator <=(E,E)' or 'built-in C++ operator<=(E, E)' while trying to match the argument list '(E, E)' TIA, Arno -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Johannes Schaub (litb) on 29 Jan 2010 06:45 Arno wrote: > Hello, > > is this expected behavior or a bug in Visual C++ 9? > > enum E { > e1 > }; > > bool operator<=( E, E ) { > return false; > } > > void main() > { > E e1; > e1<=e1; > } > > leads to compiler error > > test6.cpp(10): could be 'bool operator <=(E,E)' > or 'built-in C++ operator<=(E, E)' > while trying to match the argument list '(E, E)' > There is no built-in C++ operator<=(E, E). Builtin overload candidates are instead added for integers, and the promotion rules will choose an unambiguous match in case you haven't overloaded with enumeration parameters. But since you have, yours is a better match. Notice that VC++ is correct if you are actually very pedantic: You have an error in your code ("void main"), and the compiler gives you a diagnostic. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Tony Delroy on 29 Jan 2010 06:44 On Jan 29, 10:19 am, Arno <ascho...(a)think-cell.com> wrote: > enum E { e1 }; > > bool operator<=( E, E ) { return false; } > > void main() > { > E e1; > e1 <= e1; > } > > test6.cpp(10): could be 'bool operator <=(E,E)' > or 'built-in C++ operator<=(E, E)' > while trying to match the argument list '(E, E)' I didn't bother digging through the Standard, but it compiles under SparcWorks 5.8 and GNU 3.4.3 (after changing main()'s return type to int)... Cheers, Tony -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Klaus Rudolph on 29 Jan 2010 06:48 Hi, compiles on g++ 4.5 with c++0x and also older 4.2.1 without problems (main is not void, use int instead). > enum E { > e1 > }; > > bool operator<=( E, E ) { > return false; > } > > void main() > { > E e1; ?? Should it be E val=e1; ?? > e1<=e1; and val<=val; ?? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bob on 29 Jan 2010 10:44
On Jan 30, 12:48 am, Klaus Rudolph <lts-rudo...(a)gmx.de> wrote: > Hi, > > compiles on g++ 4.5 with c++0x and also older 4.2.1 without problems > (main is not void, use int instead). > Hi, slightly modified code: enum E { e1 }; bool operator<=(const E &, const E &) { return false; } int main() { E val = e1; val<=val; } gives: test.cpp:12: error: ambiguous overload for 'operator<=' in 'val <= val' test.cpp:12: note: candidates are: operator<=(E, E) <built-in> test.cpp:12: note: operator<=(int, int) <built-in> test.cpp:5: note: bool operator<=(const E&, const E&) with g++ 4.4.1 (TDM-2 mingw32) -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |