Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++.moderated > #1414

ambiguous operator on Visual Studio 2010

Message-ID <959a4hFnk8U1@mid.individual.net> (permalink)
Newsgroups comp.lang.c++.moderated
From "Aaron Gray" <ang.usenet@gmail.com>
Subject ambiguous operator on Visual Studio 2010
Organization unknown
Date 2011-06-08 17:23 -0600

Show all headers | View raw


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


-- 
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

Back to comp.lang.c++.moderated | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

ambiguous operator on Visual Studio 2010  "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 17:23 -0600
  Re: ambiguous operator on Visual Studio 2010  Gnawme <norm.evangelista@gmail.com> - 2011-06-09 07:00 -0600
  Re: ambiguous operator on Visual Studio 2010  Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-06-09 07:03 -0600

csiph-web