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


Groups > comp.lang.c++ > #6420

ambiguous operator on Visual Studio 2010

From "Aaron Gray" <ang.usenet@gmail.com>
Newsgroups comp.lang.c++
Subject ambiguous operator on Visual Studio 2010
Date 2011-06-08 14:09 +0100
Message-ID <959al7FrddU1@mid.individual.net> (permalink)

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

Back to comp.lang.c++ | 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 14:09 +0100
  Re: ambiguous operator on Visual Studio 2010 Victor Bazarov <v.bazarov@comcast.invalid> - 2011-06-08 09:26 -0400
    Re: ambiguous operator on Visual Studio 2010 "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 14:58 +0100
      Re: ambiguous operator on Visual Studio 2010 "Aaron Gray" <ang.usenet@gmail.com> - 2011-06-08 17:22 +0100
        Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-08 18:47 +0200
          Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-08 11:40 -0700
          Re: ambiguous operator on Visual Studio 2010 "Bo Persson" <bop@gmb.dk> - 2011-06-08 21:29 +0200
            Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-08 21:50 +0200
              Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-08 16:06 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 03:20 +0200
                Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-09 03:00 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 20:46 +0200
                Re: ambiguous operator on Visual Studio 2010 Krice <paulkp@mbnet.fi> - 2011-06-09 23:08 -0700
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-10 02:33 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-10 12:26 +0200
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-09 04:52 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-09 20:51 +0200
                Re: ambiguous operator on Visual Studio 2010 Öö Tiib <ootiib@hot.ee> - 2011-06-10 01:58 -0700
                Re: ambiguous operator on Visual Studio 2010 "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-06-10 12:36 +0200
            Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-09 13:32 +0200
          Re: ambiguous operator on Visual Studio 2010 "Balog Pal" <pasa@lib.hu> - 2011-06-10 12:24 +0200

csiph-web