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-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!news.zanker.org!newsfeeds.phibee.net!news.clara.net!wagner.news.clara.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Classwide Parameter? Date: 11 Oct 2004 20:16:41 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1097522578 15694 62.49.19.209 (11 Oct 2004 19:22:58 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Mon, 11 Oct 2004 19:22:58 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: g2news1.google.com comp.lang.ada:5052 Date: 2004-10-11T20:16:41+01:00 List-Id: matthias_k writes: > 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); Replace this with procedure Draw (Obj : Shape) is abstract; as in package Graphics is type Shape is abstract tagged null record; 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; with Ada.Text_IO; use Ada.Text_IO; package body Graphics is procedure Draw (Obj: Circle) is begin Put_Line ("circle"); end Draw; procedure Draw (Obj: Square) is begin Put_Line ("square"); end Draw; end Graphics; 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 ); end; (use gnatchop) which said smaug.pushface.org[2]$ gnatmake demo gcc -c demo.adb gcc -c graphics.adb gnatbind -x demo.ali gnatlink demo.ali smaug.pushface.org[3]$ ./demo circle square smaug.pushface.org[4]$ If you say type Reference is access all Shape'Class; then your procedure procedure Draw (Obj: Shape'Class); is bound to get called, since A_Reference.all is a Shape'Class. -- Simon Wright 100% Ada, no bugs.