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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8047848c4805a99e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Classwide Parameter? Date: Tue, 12 Oct 2004 10:10:37 +0200 Organization: AdaCL Message-ID: <14269526.aqDQ52X6SC@linux1.krischik.com> References: Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1097571568 03 1631 gGPoXFkO3EiNHJs 041012 08:59:28 X-Complaints-To: usenet-abuse@t-online.de X-ID: V35ZcZZlYeBj7fCZpZVpxyx5-kVj0ljvdwRHTnRzj9I9pteHwKxO6x User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:5078 Date: 2004-10-12T10:10:37+02:00 List-Id: matthias_k wrote: > Thanks for that answer. However, I'm still having problems (I have > rewritten the code to be in one single package now): > > > package Graphics is > > type Shape is abstract tagged null record; > procedure Draw (Obj: Shape'Class); You want an abstract method not a class wide procedure: procedure Draw (Obj: Shape) is abstract; > > type Circle is new Shape with record > Radius: Float; > Center: Float; > end record; > procedure Draw (Obj: Circle); > > type Square is new Shape with record > Size: Float; > end record; > procedure Draw (Obj: Square); > > end; > > > Now, what I want is to have different implementations of the Draw method > for each Subtype. However, if I run this program: > > > with Graphics; > use Graphics; > > procedure Demo is > type Reference is access all Shape'Class; > Object: Reference; > begin > Object := new Circle; > Draw( Object.all ); > > Object := new Square; > Draw( Object.all ); Only use pointer in Ada if you realy need to: Test_1: declare Object: Shape'Class := Circle'(Radius => 10.0, Center => 10.0); begin Draw( Object); end Test_2: declare Object: Shape'Class := Square'(Size => 10.0); begin Draw( Object); end > end; > > > The Shape's Draw method is always called here but it shouldn't. No late > binding happens. I have tried to make it abstract, but it didn't even > compile then. What's wrong? > > - Matthias -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com