Topic: Converting operands of built-in operators


Author: b91926@fnclub.fnal.gov (David Sachs)
Date: 22 Sep 1993 19:15:22 GMT
Raw View
Is there any consistent standard as to when user defined conversions may be used for built-in operators?

In all of the following examples s is a member of a class, that has the indicated conversion member function, and no other conversion member functions or overloaded operators, that could cause ambiguity.


A)   s+1     where s has a conversion to an integral type.

C++ compilers support this. The ARM explicitly allows such code.




B)   s[1]    where s has a conversion to a pointer type.

According to Rob Murray, cfront supports this construct. Some C++ compilers flag this as an error.

I see no functional difference between the subscripting and other "normal" binary operators, except that subscripting is written out slightly differently.

The ARM contains no justification whatsoever for requiring that an overloaded operator[] must be a member function. My best guess is that it was just easier to code a translator that way.


C)   s(1)    where s has a conversion to a pointer (or reference) to a function accepting an integer argument.

I see nothing in the ARM actually prohibiting this. I would like to hear if anyone knows of a C++ compiler, that accepts such usage.

I feel that the C++ standard should prohibit a user conversion to directly reach a function name.


D)   s->a    where s has a conversion to a pointer type, and the object of the pointer type has a member named a.

No opinion.