From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-28 00:27:29 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. Date: Tue, 28 Jan 2003 09:27:27 +0100 Message-ID: <3afc3v4uur2kvd53v4ul18b5npjfm188o3@4ax.com> References: <1043339266.922562@master.nyc.kbcfp.com> <7iLY9.2401$qb1.464@nwrddc01.gnilink.net> <1043680098.61106@master.nyc.kbcfp.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1043742447 32293001 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:33474 Date: 2003-01-28T09:27:27+01:00 List-Id: On Mon, 27 Jan 2003 10:08:17 -0500, Hyman Rosen wrote: >Dmitry A. Kazakov wrote: >> If I define a method or a free a procedure on Ellipse: >> void Foo (Ellipse& A); >> then the compiler will not substitute a Circle for Ellipse. > >Oh, You want to do *that* :-) Surely, isn't Circle an Ellipse? (:-)) > It's an odd sort of thing to >want to do, but if you did, you wouldn't do it with copy-in/ >copy-out, at least in C++. If I had to, I would do it like this, >in typical OO fashion: > >struct EllipseInterface >{ > virtual void set(double x, double y) = 0; > virtual void get(double &x, double &y) const = 0; >}; > >class Ellipse : public EllipseInterface >{ > double X, Y; >public: > Ellipse(double x, double y) : X(x), Y(y) { } > void set(double x, double y) { X = x; Y = y; } > void get(double &x, double &y) const { x = X; y = Y; } >}; > >class Circle : public EllipseInterface >{ > double R; >public: > struct NotCircle { }; > Circle(double r) : R(r) { } > void set(double x, double y) { R = x == y ? x : throw NotCircle(); } > void get(double &x, double &y) const { x = R; y = R; } >}; > >void Foo (EllipseInterface &A); But that's another thing. Here, Circle cannot use (inherit) the methods of Ellipse. It inherits only the abstract methods of EliipseInterface and thus, have to implement all of them for scratch. This kills the whole idea of inheritance for code reuse. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de