Path: utzoo!attcan!uunet!world!decwrl!fernwood!lia!jgro From: jgro@lia (Jeremy Grodberg) Newsgroups: comp.lang.c++ Subject: Re: operator++() and testing 'this' Message-ID: <1990Oct2.230449.9310@lia> Date: 2 Oct 90 23:04:49 GMT References: <706@msor0.UUCP> Reply-To: jgro@lia.com (Jeremy Grodberg) Lines: 52 In article <706@msor0.UUCP> kt@msor.UUCP (Keith Tizzard) writes: >Can anyone please help. > >1 operator++() > >I fully understand that if I write my own function for operator++() in >a class, I cannot detect in that function whether the operator is being >used in a prefix form or a postfix form. In E&S, pp 338-339, they explain that you now can tell which call is being made, becuase when operator++ (or operator --) is called as a postfix operator, the function will be called with an int argument of 0. >However when it is, in fact, >used why does the postfixing and prefixing not take place in the usual way? > >class X{ > .... > public: > X& operator=(x&); > X& operator++(); > . . . >}; > > >X a,b; > >a = ++b; >a = b++; > >Is it not possible for the usual arrangement whereby the ++ is performed before >= in the first, and after it in the second? > The postfix ++ simply means that the value of the expression is the value before incrementing the variable. Take you favorite ANSI C compiler and try int x = 1; x = x++; printf("x = %d\n", x); If I recall the ANSI spec correctly, the final value of x is allowed to be either 1 or 2, because the only guarantee about when the increment takes place is that it takes place before the next "sequence point," which is basically the next function call, conditional, or comma operator. -- Jeremy Grodberg "I don't feel witty today. Don't bug me." jgro@lia.com