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,8ed693b245ee5483,start X-Google-Attributes: gid103376,public From: "Anna Esparcia" Subject: hash tables and class-wide types as fields in a record Date: 2000/02/02 Message-ID: <38986a06.0@noticias.ncsa.es>#1/1 X-Deja-AN: 580880528 Organization: Telefonica Transmision de Datos X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Newsgroups: comp.lang.ada Date: 2000-02-02T00:00:00+00:00 List-Id: I'm trying to build a (generic) hash table that can store data belonging to various subclasses of a base class - which subclass won't be known till run time. The code is as follows: generic type DATA_TYPE is tagged private; type IDENT_TYPE is private; TABLE_SIZE : POSITIVE; --- type ELEMENT_TYPE; type INDEX_TYPE is access all ELEMENT_TYPE; type ELEMENT_TYPE is record DATA : DATA_TYPE; IDENT : IDENT_TYPE; NEXT : INDEX_TYPE:= null; end record; HASH_TABLE : array(0..TABLE_SIZE-1) of INDEX_TYPE:= (others => null); What i would like to do is this: DATA : DATA_TYPE'Class; so that i could store objects of type DATA_TYPE or any of its subclasses, but the compiler doesn't like it 'cos it's an "unconstrained subtype in component declaration" Now, I could declare a type pointer as follows: type DATA_POINTER is access all DATA_TYPE'Class; and an object of this type could point to any object of type DATA_TYPE or any of its subclasses. So, in my record above i can declare: DATA : DATA_POINTER; and the compiler accepts it, but when i add objects to the table the pointers end up pointing to nothing (when the actual objects disappear). Now, i could declare the record as originally (with DATA : DATA_TYPE, i.e. an object and not a pointer) but do the argument passing in the methods with pointers e.g. i would have a method ADD(p: DATA_POINTER) which would copy the object pointed to by p into the field DATA of the record. But the compiler doesn't let me do this either. Any ideas? Any other way of implementing the hash table? BTW the hash tables will be in shared memory and once they've been created they'll stay there forever, so that they can be accessible to anybody. Can i copy the objects pointed to onto global objects in this shared memory so that they don't vanish into thin air? Will this defeat the whole point of having a hash table? Anna