* Problem with dynamic dispatching (Polymorphism)
@ 1999-04-25 0:00 Mattias
1999-04-25 0:00 ` Bo Sanden
0 siblings, 1 reply; 2+ messages in thread
From: Mattias @ 1999-04-25 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1314 bytes --]
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 occures when I wan't to
extract the data and Print it to the screen..
look at the following code example:
program.ads:
type T�cken is tagged null record;
type Siffra is new Tecken with
Record
Element : Integer;
end record;
procedure Print(S : Siffra);
type Bokstav is new T�cken 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
Pocedure 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Problem with dynamic dispatching (Polymorphism)
1999-04-25 0:00 Problem with dynamic dispatching (Polymorphism) Mattias
@ 1999-04-25 0:00 ` Bo Sanden
0 siblings, 0 replies; 2+ messages in thread
From: Bo Sanden @ 1999-04-25 0:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-04-25 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-25 0:00 Problem with dynamic dispatching (Polymorphism) Mattias
1999-04-25 0:00 ` Bo Sanden
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox