Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cmcl2!nrl-cmf!think!snorkelwacker!bloom-beacon!eru!luth!sunic!sics.se!sics.se!levitte From: levitte@garbo.bion.kth.se (Tommy Levitte) Newsgroups: comp.lang.c++ Subject: ++ bug ? Message-ID: Date: 14 Oct 89 09:36:40 GMT Sender: news@sics.se Distribution: comp Organization: Royal Institute of Technology, Stockholm Lines: 68 A few articles ago, somebody talked about extending C++ with the operators ++@ and @++ . I didn't understand the use of it, thinking C++ handled it the right way anyway. I wanted to check, though, and made the following test: // ----------8<------------------------------------------- #include "stream.h" class complex { int Re,Im; public: complex() {this->Re=0; this->Im=0;} complex(int Re) {this->Re=Re; this->Im=0;} complex(int Re,int Im) { this->Re=Re; this->Im=Im;} complex operator=(int i) { this->Re=i; this->Im=0; return *this;} complex operator++() { return *this=*this+1; } complex operator+(int i) { return complex(this->Re+i,this->Im); } int re() { return this->Re; } int im() { return this->Im; } }; ostream& operator<<(ostream& foo,complex& bar) { return foo << "(" << bar.re() << "," << bar.im() << ")"; } main() { complex h,i,j,k; h=i=1; j=h++; cout << j << " " << h << "\n"; k=++i; cout << k << " " << i << "\n"; } //----8<------------------------------------------------------------- This was compiled (translated, I mean) by AT&T C++ version 1.2 . The output is the following : (2,0) (2,0) (2,0) (2,0) Now, my question is : Is this a bug in version 1.2 or should C++ act like that ???? It looks like use implemented operator++ always behaves like ++v, even when you have written v++ !!!!!! With a "normal" behaviour, the output should be : (1,0) (2,0) (2,0) (2,0) Does anybody have an explanation to this ??? Tommy Levitte gizmo@nada.kth.se gizmo@kicki.stacken.kth.se gizmo@ttt.kth.se -- Tommy Levitte gizmo@nada.kth.se gizmo@kicki.stacken.kth.se gizmo@ttt.kth.se