schmidt@crimee.ics.uci.edu (Doug Schmidt) (05/09/89)
Since people seem in the mood to disambiguate obscure C++ language
design points I have a quick question about the following piece of
code from page 313 in the 1988 USENIX C++ Conference Proceedings.
----------------------------------------
class X
{
public:
X ();
X (X& x, int X::*p);
operator int X::*();
protected:
int i;
double d;
};
f ()
{
X a;
int X::* pi_X = a;
X b = X (a, pi_X);
X *px = new X (a, b);
// stuff omitted...
a.*pi_X = *px.*b // evaluated as ((*px).*)b.operator int X::*()
}
----------------------------------------
This last line of code does not make any sense to me, especially since
the precedence of the new operators .* and ->* (shown on page 311) are
HIGHER than * (i.e., the dereference operator).
Was this just a typo in the article? Does C++ 2.0 really evaluate
things this way?!?!
thanks,
Doug
--
On a clear day, under blue skies, there is no need to seek.
And asking about Buddha +------------------------+
Is like proclaiming innocence, | schmidt@ics.uci.edu |
With loot in your pocket. | office: (714) 856-4043 |turner@sdti.SDTI.COM (Prescott K. Turner) (05/10/89)
In article <13718@paris.ics.uci.edu> Doug Schmidt <schmidt@crimee.ics.uci.edu> writes: X * px; ... > a.*pi_X = *px.*b; // evaluated as ((*px).*)b.operator int X::*() >Was this just a typo in the article? Does C++ 2.0 really evaluate >things this way?!?! It's got at least one typo independent of the question you raised. You can never put a parenthesis between an operator and its operand. Fixing this gives a.*pi_X = *px.*b; // evaluated as (*px).*(b.operator int X::*()) Cfront 1.2, which also supports pointers to members, accepts a.*pi_X = (*px).*(b.operator int X::*()); and rejects a.*pi_X = *px.*(b.operator int X::*()); so it is very likely that the article meant to say a.*pi_X = (*px).*b; // evaluated as (*px).*(b.operator int X::*()) -- Prescott K. Turner, Jr. Software Development Technologies, Inc. P.O. Box 366, Sudbury, MA 01776 USA (508) 443-5779 UUCP: ...{harvard,mit-eddie}!sdti!turner Internet: turner@sdti.sdti.com
rfg@riunite.ACA.MCC.COM (Ron Guilmette) (05/14/89)
In article <455@sdti.SDTI.COM> turner@sdti.UUCP (0006-Prescott K. Turner, Jr.) writes: >You can never put a parenthesis between an operator and its operand. I think you meant "you can never put a closing parenthesis between an operator and it operand." Actually though, I don't believe that this is strictly true either. For example, aren't these legal? (*ptr)++ (*ptr)-- -- // Ron Guilmette - MCC - Experimental Systems Kit Project // 3500 West Balcones Center Drive, Austin, TX 78759 - (512)338-3740 // ARPA: rfg@mcc.com // UUCP: {rutgers,uunet,gatech,ames,pyramid}!cs.utexas.edu!pp!rfg