From: Martin Krischik <krischik@users.sourceforge.net>
Subject: Re: Classwide Parameter?
Date: Tue, 12 Oct 2004 10:10:37 +0200
Date: 2004-10-12T10:10:37+02:00 [thread overview]
Message-ID: <14269526.aqDQ52X6SC@linux1.krischik.com> (raw)
In-Reply-To: ckeelg$dkb$05$1@news.t-online.com
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):
>
> <snip>
> 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;
> </snip>
>
> Now, what I want is to have different implementations of the Draw method
> for each Subtype. However, if I run this program:
>
> <snip>
> 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;
> </snip>
>
> 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
prev parent reply other threads:[~2004-10-12 8:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-10-11 16:01 Classwide Parameter? matthias_k
2004-10-11 16:53 ` Matthew Heaney
2004-10-11 17:08 ` matthias_k
2004-10-11 19:16 ` Simon Wright
2004-10-11 22:53 ` Brian May
2004-10-12 2:29 ` Matthew Heaney
2004-10-12 8:01 ` matthias_k
2004-10-12 8:53 ` Martin Krischik
2004-10-12 13:10 ` Matthew Heaney
2004-10-12 7:59 ` Dmitry A. Kazakov
[not found] ` <ckg3h6$qau$03$1@news.t-online.com>
2004-10-12 8:14 ` matthias_k
2004-10-12 15:13 ` Dmitry A. Kazakov
2004-10-12 8:10 ` Martin Krischik [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox