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: Mark & Zurima McKinney Subject: Re: passing pointer of different type to one procedure Date: 1997/04/18 Message-ID: <3357BA42.654F@us.net>#1/1 X-Deja-AN: 235730272 References: <01bc4a80$713ca380$52bd0c26@cat> To: Boaz Organization: US Net - MD,DC,VA ISP - info@us.net Newsgroups: comp.lang.ada Date: 1997-04-18T00: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; > --You can make then the same type with a discriminant record ... --Link so ... type record_types is (A, B); type Keyed_Record(Record_Type : Record_Types) is record Key : Float; case Record_Type is when A => I : Integer; when B => F : Float; end case; end record; --Now the ponter will bee of one type and can point to 2 or more different types of --discriminant records. type Keyed_Record_Pointer is access Keyed_Record; --It is likely that you would want to sort an array particularly if there --will be more than two items to sort. type Keyed_Record_Pointer_Arrays is array(natural range <>) of Keyed_Record_Pointer; --this might also be useful function "<"(Left, Right : in Keyed_Record) return Boolean is begin return Left.Key < Right.Key; end; In Ada95 you can also use inheritance. type keyed_class is tagged record Key : Float; end record; type key_record_pointer is access all keyed_Class; function "<"(Left, Right : Keyed_Class'Class) return boolean is ...... --perhaps in a child package type integer_keyed_class is new keyed_class with record I : integer; end record; --perhaps in a another child package type float_keyed_class is new keyed_class with record F : float; end record; Enough said this should point you in the right direction. MArk McKinney