Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!apple!snorkelwacker!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!strath-cs!expya!msor!kt From: kt@msor.UUCP (Keith Tizzard) Newsgroups: comp.lang.c++ Subject: operator++() and testing 'this' Message-ID: <706@msor0.UUCP> Date: 25 Sep 90 14:54:20 GMT Reply-To: kt@msor.UUCP (Keith Tizzard) Organization: MSOR Department, Exeter University, UK Lines: 57 Two questions about C++ 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. 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? 2 Testing of and assigning to 'this' Before version 2.0 if one wanted to allocate space for an object, one way was to test the value of 'this' within the constructor to detect whether the object was to be on the free store or not if(this == 0) this = malloc( .... else this = this; In V2.0 this is not longer needed since overloading operator new and operator delete is preferred. Is is still possible to assign to 'this' in V2.0? Can one rely on 'this' having the value zero one entry to the constructor is the object is allocated on the free store? Is there any neeed to do it at all? -- Keith Tizzard MSOR Dept, University of Exeter, Streatham Court, EXETER EX4 4PU, UK tel: (+44) 392 264463 email: kt@msor.exeter.ac.uk kt@msor.UUCP