From: Vladimir Grigoriev on
May I write operator ==( 10, 20 ) ?

Vladimir Grigoriev


From: Victor Bazarov on
Vladimir Grigoriev wrote:
> May I write operator ==( 10, 20 ) ?

No, the Standard explicitly prohibits overloading operators for built-in
types (Standard, [Expr]/3). Since 10 and 20 are of built-in type, int,
you can't define an operator that would potentially alter the behaviour
of the equality operator defined by the Standard.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
From: Stephan T. Lavavej [MSFT] on
That's why you can't define operator==(int, int). The reason why you can't
call operator==(10, 20) is different.

C++03 13.6 [over.built]/1:

"The candidate operator functions that represent the built-in operators
defined in clause 5 are specified in
this subclause. These candidate functions participate in the operator
overload resolution process as
described in 13.3.1.2 and are used for no other purpose. [Note: because
built-in operators take only
operands with non-class type, and operator overload resolution occurs only
when an operand expression
originally has class or enumeration type, operator overload resolution can
resolve to a built-in operator only
when an operand has a class type that has a user-defined conversion to a
non-class type appropriate for the
operator, or when an operand has an enumeration type that can be converted
to a type appropriate for the
operator."

STL

"Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message
news:hjkndu$1df$1(a)news.datemas.de...
> Vladimir Grigoriev wrote:
>> May I write operator ==( 10, 20 ) ?
>
> No, the Standard explicitly prohibits overloading operators for built-in
> types (Standard, [Expr]/3). Since 10 and 20 are of built-in type, int,
> you can't define an operator that would potentially alter the behaviour of
> the equality operator defined by the Standard.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask

From: Vladimir Grigoriev on
In the "C++ in a nutshell" of Ray Lischner is written

You can use the function notation with
built-in operators, too, but such usage is extremely uncommon. For example:
operator-(42, 10) // Same as 42 - 10
operator-(33) // Same as -33

Vladimir Grigoriev

"Stephan T. Lavavej [MSFT]" <stl(a)microsoft.com> wrote in message
news:O57zRwfnKHA.4648(a)TK2MSFTNGP06.phx.gbl...
> That's why you can't define operator==(int, int). The reason why you
> can't call operator==(10, 20) is different.
>
> C++03 13.6 [over.built]/1:
>
> "The candidate operator functions that represent the built-in operators
> defined in clause 5 are specified in
> this subclause. These candidate functions participate in the operator
> overload resolution process as
> described in 13.3.1.2 and are used for no other purpose. [Note: because
> built-in operators take only
> operands with non-class type, and operator overload resolution occurs only
> when an operand expression
> originally has class or enumeration type, operator overload resolution can
> resolve to a built-in operator only
> when an operand has a class type that has a user-defined conversion to a
> non-class type appropriate for the
> operator, or when an operand has an enumeration type that can be converted
> to a type appropriate for the
> operator."
>
> STL
>
> "Victor Bazarov" <v.Abazarov(a)comAcast.net> wrote in message
> news:hjkndu$1df$1(a)news.datemas.de...
>> Vladimir Grigoriev wrote:
>>> May I write operator ==( 10, 20 ) ?
>>
>> No, the Standard explicitly prohibits overloading operators for built-in
>> types (Standard, [Expr]/3). Since 10 and 20 are of built-in type, int,
>> you can't define an operator that would potentially alter the behaviour
>> of the equality operator defined by the Standard.
>>
>> V
>> --
>> Please remove capital 'A's when replying by e-mail
>> I do not respond to top-posted replies, please don't ask
>