Path: utzoo!attcan!uunet!microsoft!ilanc From: ilanc@microsoft.UUCP (Ilan CARON) Newsgroups: comp.lang.c++ Subject: Re: Multiple Inheritance Message-ID: <58411@microsoft.UUCP> Date: 20 Oct 90 20:23:35 GMT References: <9528@milton.u.washington.edu> Reply-To: ilanc@microsoft.UUCP (Ilan CARON) Distribution: na Organization: Microsoft Corp., Redmond WA Lines: 67 In article <9528@milton.u.washington.edu > you write: [I've edited the classes, leaving the important stuff...] > > class Point > { > public: > }; > > class PhysicalPoint : Point > { > public: > PhysicalPoint(short x, short y); > }; > > class LogicalPoint : Point > { > public: > LogicalPoint(); > LogicalPoint(double wx, double wy); > } > > class Rectangle > { > Rectangle(Point *ul, Point *dr); > }} > > > Now with the above definitions I should be able to do this (in TC++) > right? > > LogicalPoint *lPoint = new LogicalPoint(10.0, 10.0); > LogicalPoint *lPoint2 = new LogicalPoint(30.0, 30.0); > > PhysicalPoint *pPoint1 = new PhysicalPoint(10, 10); > PhysicalPoint *pPoint2 = new PhysicalPoint(30, 30); > > Rectangle lRect(lPoint1, lPoint2); > Rectangle pRect(pPoint1, pPoint2); > --------------------- > bytor@milton.u.washington.edu Hi, Well, one of the problems in your definitions (aside from some minor typos) is that Rectangle::Rectangle() is private (that's C++'s default accessibility. One effective way (and in this case unintentional) way of making a class "non-instantiable" by clients is to make its constructors private. Another problem is that LogicalPoint and PhysicalPoint derive *privately* from Point (again this is the default), which I'm sure you did not intend. Use e.g. class LogicalPoint : public Point {...}; The effect of the latter is that a pointer to a LogicalPoint (e.g. lPoint1) can't be cast to a pointer to a Point. Thus the following fails: Rectangle lRect(lPoint1, lPoint2); for two reasons: (1) The constructor Rectangle::Rectangle(Point*, Point*) is private. and (2) LogicalPoint derives privately from Point, hence can't cast lPoint1 and lPoint2 to Point*. Hope this helps. --ilan caron (microsoft!ilanc@beaver.cs.washington.edu)