From 412348114558289564 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,db4807a3f0a1e742 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 1994-08-05 08:22:31 PST Path: bga.com!news.sprintlink.net!nwnexus!korona!pkron From: pkron@corona.com (Peter Kron) Organization: Corona Design, Inc., Seattle, WA Reply-To: pkron@corona.com Distribution: world Date: Fri, 5 Aug 1994 06:04:45 PDT Message-ID: <1994Aug05.130445.352@corona.com> Newsgroups: comp.std.c++ Subject: Re: Multiple inheritance and delete Lines: 41 References: <776024044snz@storcomp.demon.co.uk> From: Philip@storcomp.demon.co.uk (Philip Hugh Hunt) > One example follows: > > class Point { > public: > int x; > int y; > Point(int xx =0, int yy =0) { x=xx; y=yy; }; > Point operator+(Point p) {return Point(x+p.x, y+p.y);}; > }; class ConstrainedPoint : Point { public: int limit; Point operator+(Point p) {return Point( x+p.x < limit ? x+p.x : limit, y+p.y)}; } If this class is used in a collection of Point, it is probably going to cause some subtle bugs. It's probably guaranteed to happen in the maintenance of any software using Point. Since this use--which seems reasonable enough--wasn't anticipated by the designer of Point, the reuse of Point is limited. Why should this be the default? > If this class was forced to be polymophic, it would be > less efficient. The loss of efficiency would probably > be unacceptable if this class was used in eg a windowing > system. I could certainly produce a benchmark supporting your claim. I could also show that using a simple C struct would improve performance further. However, in a real system, I'd be more concerned about the total efficiency. If a polygon of a 1000 points is translated using operator+, which will contribute more to the overall performance: memberfunction calls or rerendering the polygon following translation? --- NeXTMail:peter.kron@corona.com Corona Design, Inc. P.O. Box 51022 Seattle, WA 98115-1022