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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,18684ed750c9b60f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.224.183.13 with SMTP id ce13mr10263304qab.4.1349579194207; Sat, 06 Oct 2012 20:06:34 -0700 (PDT) Received: by 10.236.115.33 with SMTP id d21mr1494032yhh.12.1349579194184; Sat, 06 Oct 2012 20:06:34 -0700 (PDT) Path: e10ni211270746qan.0!nntp.google.com!l8no29008098qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 6 Oct 2012 20:06:34 -0700 (PDT) In-Reply-To: <527f8487-a578-406c-86c3-b3b0596cda71@l32g2000yqb.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=68.4.246.214; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ NNTP-Posting-Host: 68.4.246.214 References: <51f8461d-d362-4e5f-a188-ac96a699a211@googlegroups.com> <527f8487-a578-406c-86c3-b3b0596cda71@l32g2000yqb.googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to get generic formal parameter type into base class From: Adam Beneschan Injection-Date: Sun, 07 Oct 2012 03:06:34 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-10-06T20:06:34-07:00 List-Id: On Saturday, October 6, 2012 1:03:34 PM UTC-7, kevin andrew wrote: > I still don't see how to get a dynamic type into base class so that I > can dispatch to a function with that type in the function signature. > If I do a Root_Type then I don't see how I can include the Get/ > Set_Value function because Data_Type is unknown?=20 Right. It was a bit late when I posted my response, so I didn't notice tha= t Get/Set_Value would involve different result/parameter types so it couldn= 't be defined for the root type. But if the procedure involves different r= esult/parameter types, you can't really **dispatch** to it, can you? For d= ispatching to work (and I think this applies to C++ and other OO languages = as well), the types of everything except your Xlate_Type or Xlate_Base_Type= have to be known; then the program decides at runtime which is the correct= procedure or function to call. In your case, I think what you want is this: Define Encode and Decode for y= our root type, but not Get_Value or Set_Value. Go ahead and define Get_Val= ue and Set_Value in the generic, but note that each instantiation of the ge= neric will produce a different, and unrelated, declaration of Get_Value or = Set_Value. Since they're unrelated, you can't use a dispatching call to ca= ll them. But your code wasn't trying to do that. (In essence, you were us= ing your own CASE statement to do a fake "dispatch".) So when you wrote: > when Int_100 =3D> > Msg.theInt :=3D Classes.Translate_Base.Get_Value(Class); -- if Class is declared with type Your_Root_Type'Class, you'll need to convert= it to the specific type, and call the function declared in the specific ge= neric instance: when Int_100 =3D> Msg.theInt :=3D Objects.Int_100.Get_Value=20 (Objects.Int_100.Xlate_Type(Class)); or, more simply: when Int_100 =3D> Msg.theInt :=3D Objects.Int_100.Xlate_Type(Class).Get_Value; Objects.Int_100.Xlate_Type(Class) is a kind of "type conversion" that tells= the compiler that Class, which is declared as Your_Root_Type'Class, actual= ly has the type Objects.Int_100.Xlate_Type (and it will check at run time t= hat this is true, and raise an exception if not). Please note, I'm at home and don't have easy access to an Ada compiler, so = I can't try this myself to make sure it works. Hope this helps, -- Adam