Aaron Gray
2011-06-08 13:15:39 UTC
Hello,
I am getting an ambiguous operator error in VS2010 but not in GCC 4.5.
The following code illustrates the problem :-
enum flags { OK, TEST };
inline bool operator >= (flags f1, flags f2) {
return (f1 & f2) == f2;
}
int main(int argc, char *argv[]) {
flags f1 = OK;
flags f2 = TEST;
bool b = f1 >= f2;
return 0;
}
gives the following on VS2010 :-
1> test.cpp
1>c:\test\c++\operator-test\operator-test\test.cpp(10): error C2593:
'operator >=' is ambiguous
1> c:\test\c++\operator-test\operator-test\test.cpp(3): could be 'bool
operator >=(flags,flags)'
1> or 'built-in C++ operator>=(flags, flags)'
1> while trying to match the argument list '(flags, flags)'
What is the correct ISO C++ 2004 behaviour ?
Is there a workaround other than defining a function 'bool
superset(flags,flags)' instead of operator >= ?
Many thanks in advance,
Aaron
I am getting an ambiguous operator error in VS2010 but not in GCC 4.5.
The following code illustrates the problem :-
enum flags { OK, TEST };
inline bool operator >= (flags f1, flags f2) {
return (f1 & f2) == f2;
}
int main(int argc, char *argv[]) {
flags f1 = OK;
flags f2 = TEST;
bool b = f1 >= f2;
return 0;
}
gives the following on VS2010 :-
1> test.cpp
1>c:\test\c++\operator-test\operator-test\test.cpp(10): error C2593:
'operator >=' is ambiguous
1> c:\test\c++\operator-test\operator-test\test.cpp(3): could be 'bool
operator >=(flags,flags)'
1> or 'built-in C++ operator>=(flags, flags)'
1> while trying to match the argument list '(flags, flags)'
What is the correct ISO C++ 2004 behaviour ?
Is there a workaround other than defining a function 'bool
superset(flags,flags)' instead of operator >= ?
Many thanks in advance,
Aaron