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-7-bit X-Google-Thread: 103376,bf0a6e5321bcc595 X-Google-Attributes: gid103376,public From: John Harbaugh Subject: Re: passing pointer of different type to one procedure Date: 1997/04/17 Message-ID: <33568C14.4337@boeing.com>#1/1 X-Deja-AN: 235547815 Sender: nntp@news.boeing.com (Boeing NNTP News Access) X-Nntp-Posting-Host: elaptop.knt.boeing.com References: <01bc4a80$713ca380$52bd0c26@cat> Organization: Boeing Defense and Space Group - Employee Training Newsgroups: comp.lang.ada Date: 1997-04-17T00:00:00+00:00 List-Id: Boaz wrote: > > Hi there, > > I am trying to write a sort procedure for a data base project. I have 2 > different records. Instead of having 2 instances for that sort procedure, > I am thinking to use just one that take a pointer of either one of the > records type. > > this is my test program but I don't quite sure how to set it up : > > with text_io; use text_io; > with ada.float_text_io; use ada.float_text_io; > > procedure test is > > type record_pointer is access all record; <-- error > > type a is record > key : float; > d : integer; > end record; > > type b is record > key : float; > e : float; > end record; > > rp : record_pointer; > d1 : aliased a; > d2 : aliased b; > > procedure sort(p : in record_pointer) is > begin > put(p.key); > end sort; > > begin > > d1.key := 1.0; > d2.key := 5.0; > rp := d1'access; > sort(rp); > rp := d2'access; > sort(rp); > end test; Perhaps you could create records as a class hierarchy of tagged types, then pass a class-wide pointer to your sort routine. Cheers, - John