Path: utzoo!utgpu!watmath!iuvax!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!m.cs.uiuc.edu!rchen From: rchen@m.cs.uiuc.edu Newsgroups: comp.lang.c++ Subject: Re: Once again, Zortech C++ problem Message-ID: <4800072@m.cs.uiuc.edu> Date: 13 Aug 89 22:16:00 GMT References: <24@<19036> Lines: 41 Nf-ID: #R:<19036:24:m.cs.uiuc.edu:4800072:000:1284 Nf-From: m.cs.uiuc.edu!rchen Aug 13 17:16:00 1989 /* Try to run the following program and explain why point b is trashed, whereas c is not. If you take the comments out, everything works just fine. However, if I take the comments out in my program, I'll get "ZTC bug: nnnn" at compile time. Still, it doesn't quite explain why my program worked SOMETIMES depending on certain magic code combinations. I used "ztc -a -b -s -r -cpp -mL -S prog.c" to compile this file. By the way, this program gives correct results by using AT&T C++ 1.2 */ #includeclass Point { int xc, yc; Point(int x, int y) { xc = x; yc = y; } // Point(Point& p) { xc = p.xc; yc = p.yc; } Point() { xc = 0; yc = 0; } ~Point() { } public: int x() { return xc; } int y() { return yc; } // Point& operator=(Point&); Point operator+(Point&); }; // Point& Point::operator=(Point& p) { xc = p.xc; yc = p.yc; return *this; } Point Point::operator+(Point& p) { Point q(xc + p.xc, yc + p.yc); return q; } main() { Point a = Point(10, 0) + Point(0, 30); Point c, b; b = Point(10, 0) + Point(0, 30); c = Point(10, 30); cout << "a = (" << a.x() << ", " << a.y() << ")\n"; cout << "b = (" << b.x() << ", " << b.y() << ")\n"; cout << "c = (" << c.x() << ", " << c.y() << ")\n"; }