From 6153207692107937346
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,9a5d91576ea14293
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,42ca30940288d269
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1992-03-02 14:20:20 PST
Xref: sparky comp.lang.c++:5506 comp.std.c++:267
Path: sparky!uunet!dtix!oasys!vorwald
From: vorwald@oasys.dt.navy.mil (John Vorwald)
Newsgroups: comp.lang.c++,comp.std.c++
Subject: Re: X to the Y power, how?
Message-ID: <16026@oasys.dt.navy.mil>
Date: 2 Mar 92 22:06:02 GMT
References: <50175@hydra.gatech.EDU> <1992Mar2.154651.12261@rice.edu>
Reply-To: vorwald@oasys.dt.navy.mil (John Vorwald)
Followup-To: comp.lang.c++
Distribution: usa
Organization: Carderock Division, NSWC, Bethesda, MD
Lines: 63

In comp.lang.c++, dougm@rice.edu (Doug Moore) writes:
>In article <9206222.13299@mulga.cs.mu.OZ.AU>, fjh@magnum.cs.mu.OZ.AU (Fergus Ja
>mes HENDERSON) writes:
>|> ... I am SICK TO DEATH of the MANY people posting INCORRECT statements to
>|> the effect that "well, using '**' would be nice, but it is impossible".
>|>
>|> It is QUITE possible to provide a simple interface that allows ** to be used
> as
>|> both for exponentiation and double-indirection.
>
>Okay.  So, if I've overloaded both unary and binary operator * for a
>class Foo, and I've overloaded the exponentiation operator ** as well,
>what is the meaning of:
>
>Foo a,b,c;
>a = b**c;  // b * (*c)?   b (**) c?
>
>Doug Moore
>(dougm@cs.rice.edu)

I'm a beginner, so don't throw flames, but
generally, I would not define an operator between a pointer and an
object.  So the only possible interpretation is

 a =  (b) (**) (c)

Since a, b, and c are of the same class.  There would be a problem if
(*c) pointed to an obect of class Foo, but then Foo is an unique class
to begin with.  I think the issue of having exponentiation is primarily
concerned with somewhat normal classes dealing with numbers: ie:  matrices,
vectors, complex numbers, real numbers, integers...

Does anyone have a real example where ** can not be correctly interperated
correctly by letting the unary operator * have precedence if the operand
is of type pointer?

  a = b **** c     is either
  a = b ** (*c)    c is a pointer to a class where ** is defined
or a = b * (**c)   c is a pointer to pointers of a class where * is
		   defined.
  One of these choices has to true, not both.  If both are true, then
the operators * and ** have been overloaded such that they are
indistuginasble (?SP).  Is there a situation where * and ** can not
be seperated out?  (Besides program or structure errors.  ie  Matrix(int)
and Matrix(int i, int j=1) can not be seperated)

  In the above example, if b is a matrix, and c is a matrix, one could
argue that a matrix raised to a vector can be defined
    a = b ** (*c)
and a matrix can be multiplied by a scalar
    a = b * (**c)

  But this error can be attributed to poor class defination, and caught by
the compiller as indistugishable code.

  I would like to see an honest evaluation of the potential to incorporate
** as an operator having the same precedence as .* or ->*.  This would
keep indirection (*) at a higher precedence, and be above the precedence
of * / % + -.

These are the thougths of a beginner (and a poor speller)
John Vorwald
vorwald@oasys.dt.navy.mil


