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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,85c103793571fa8d X-Google-Attributes: gid103376,public From: Bo Sanden Subject: Re: Problem with dynamic dispatching (Polymorphism) Date: 1999/04/25 Message-ID: <3723A359.E558E0F1@acm.org>#1/1 X-Deja-AN: 470851121 Content-Transfer-Encoding: 8bit References: <7fvfcm$cfi$1@news.lth.se> X-Accept-Language: en Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: newsabuse@remarQ.com X-Trace: 925082135.299.67 XWEESWDYPE19FD0CDC usenet1.supernews.com Organization: Posted via RemarQ Communities, Inc. MIME-Version: 1.0 NNTP-Posting-Date: Sun, 25 Apr 1999 23:15:35 GMT Newsgroups: comp.lang.ada Date: 1999-04-25T00:00:00+00:00 List-Id: 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