Article View: comp.std.c++
Article #171Re: Exponentiation operator proposal
From: Paul Lucas
Date: Tue, 15 Sep 1992 14:00
Date: Tue, 15 Sep 1992 14:00
43 lines
2576 bytes
2576 bytes
In <1992Sep15.054226.4126@cc.tut.fi> jk87377@cc.tut.fi (Juhana Kouhia) writes:
>Hi,
>I'm very new in C++ world; I have not done any programs so far;
>and I'm currently reading C++ Primer books on chapter 3 :-)
>Instead of making exponential operator; I would like to get
>a new basic operation which allows programmer to define new
>operations like 'a ** b'; that is, the '**' is defined.
>('a pow b' is also good.)
*****> The short answer is that it's a _real_ pain. The somewhat
longer answer is that making new operators means that you have
to also establish the precedence and associativity of the new
operator relative to all the other operators *AND* any other
operators created by other people. Every time an operator is
added, the hierarchy would have to be readjusted.
For new operators, the precedence and associativity may seem
arbitary at the time of creation, but it may later be realised,
after experience, that it could have been done better...of
course it's too late to change it now because code would break.
Also, if you were to use library X and library Y, each could use
the same operator for different reasons, and the two operators
were developed without regard to the others precedence and
associativity; how would the compiler resolve this? (I'm not
looking for people to show how smart they are here by telling me
how a compiler could resolve this...the point is that even if
the compiler could do it, most _people_ would have a tough time
looking at the code.)
It's more trouble than its worth. The _point_ of operator
overloading is to give an operator a _natural_ extension to
another type. People shouldn't sit around trying to figure out
how to force an operator (square peg) to be used for a new type
(round hole). If the operator's use in a new context isn't
intuitively obvious, forget it and use function-notation.
--
- Paul J. Lucas University of Illinois
AT&T Bell Laboratories at Urbana-Champaign
Naperville, IL pjl@cs.uiuc.edu
Technical Details
Message-ID:
<1992Sep15.140027.17387@sunb10.cs.uiuc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjlReferences:
<23660@alice.att.com> <HBF.92Sep14205333@durin.uio.no> <1992Sep15.054226.4126@cc.tut.fi>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++,comp.lang.c++ Path: arc1-ca.pugleaf.net!sparky!uunet!wupost!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl From: pjl@sparc10.cs.uiuc.edu (Paul Lucas) Subject: Re: Exponentiation operator proposal Message-ID: <1992Sep15.140027.17387@sunb10.cs.uiuc.edu> Sender: news@sunb10.cs.uiuc.edu Organization: University of Illinois at Urbana-Champaign References: <23660@alice.att.com> <HBF.92Sep14205333@durin.uio.no> <1992Sep15.054226.4126@cc.tut.fi> Date: Tue, 15 Sep 1992 14:00:27 GMT Lines: 43