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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a5da83ba8982e1cd,start X-Google-Attributes: gid103376,public From: woodruff@tanana.llnl.gov (John Woodruff) Subject: Q: How to declare object with known tag? Date: 1996/06/04 Message-ID: #1/1 X-Deja-AN: 158441196 distribution: world organization: Lawrence Livermore National Lab reply-to: woodruff1@llnl.gov newsgroups: comp.lang.ada Date: 1996-06-04T00:00:00+00:00 List-Id: I hope one of the Ada experts will advise me how to write the following code fragment. I would like to declare an object of a particular type, where the type is a tagged record, and I can specify which tag at run-time. Here is the fragment I would like to build: declare Trial_Tag : Ada.Tags.Tag ; type Trial_Type is access all Some_Tag.Base'Class ; Trial : Trial_Type ; begin Trial_Tag := Ada.Tags.Internal_Tag ("SOME_TAG.EXTEND21") ; -- Let user input specify the string argument to Internal_Tag -- Trial := new SOMETHING -- I dont know what ; -- Trial.all is to be an instance of some_tag.extend21 end ; The goal: I will declare a "heterogenous list" composed of various sub-types of the type declared in some_tag. I wish to append a newly-created member onto the list. I want to read a user's input to decide which subtype is to be appended. If I have my way, I'll be able to write the procedure for recognizing the user's selection *before* all the subtypes have been declared, because I want to defer the definition of "the last" legitimate subtype until after the code to accept user selection has been written and tested. Of course if the argument to Tags.Internal_Tag is wrong, I'll remonstrate with my user. I recognize that the user will need to create the object of (the new extension) of some_tag.extend21. But to my thinking, after I have successfully declared Trial.all in the example, THEN I can dispatch to the newly extended type to receive the user's input. Is this a legitimate wish? If it is not (ie it's illegal to declare a class-wide access to an object in a code written before the specific subtype has been declared) -- then what is my alternative? It would be inconvenient to declare an enumeration naming all the (future) extensions that can be appended onto the heterogenious list. -- John Woodruff N I F \ ^ / Lawrence Livermore National Lab =====---- < 0 > 510 422 4661 / v \