From: Bo Sanden <bsanden@acm.org>
Subject: Re: Problem with dynamic dispatching (Polymorphism)
Date: 1999/04/25
Date: 1999-04-25T00:00:00+00:00 [thread overview]
Message-ID: <3723A359.E558E0F1@acm.org> (raw)
In-Reply-To: 7fvfcm$cfi$1@news.lth.se
Mattias wrote:
> Hi!
>
> I�m developing a simple linked list to hold different data types..
> I have to one superclass with two derived classes..
>
> I have declared a 'Class type which I use to access all of my structures,
>
> I have no trouble adding data to the list. The error occurs when I want to
> extract the data and Print it to the screen..
>
> look at the following code example:
>
> program.ads:
> type Tecken is tagged null record;
> type Siffra is new Tecken with
> Record
> Element : Integer;
> end record;
> procedure Print(S : Siffra);
>
> type Bokstav is new Tecken with
> record
> Element : Character;
> end record;
> procedure Print(B : Bokstav);
>
> type pTecken is access all Tecken'Class;
>
> program.adb
> -- I have to simple procedures which Print the values of Class bokstav,
> '' notice .. pekare is of type pTecken ..
>
> procedure Print(B : Bokstav) is
> begin
> Put(B.Element);
> end Print;
>
> procedure Print(S : Siffra) is
> package Iio is new Integer_Io(Integer);
> use Iio;
> begin
> put(S.Element);
> end Print;
>
> -- Then I have this procedure to extract the elements from the list. Pekare
> is
> Procedure Display is
> begin
> while Lista /= null loop
>
> Print(Lista.Pekare);
> Lista := Lista.Next;
> end loop;
> end Display;
>
> Really need help on this one
>
> thx
> Mattias
You need a procedure Print (T : Tecken). It would make sense to make it
and the
type Tecken abstract.
Bo Sanden
Colorado Tech
Colorado Springs
prev parent reply other threads:[~1999-04-25 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-25 0:00 Problem with dynamic dispatching (Polymorphism) Mattias
1999-04-25 0:00 ` Bo Sanden [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