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: 103376,dad94612ff745427 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.net!fi.sn.net!newsfeed2.fi.sn.net!feeder2.news.jippii.net!feeder1.news.jippii.net!nntp.inet.fi!inet.fi!newsfeed1.nokia.com!news1.nokia.com!news2.nokia.com.POSTED!not-for-mail From: rick H Subject: Re: Instantiating private types with discriminants? Newsgroups: comp.lang.ada References: <1147252198.138173.203910@j73g2000cwa.googlegroups.com> <1147270882.727958.212080@u72g2000cwu.googlegroups.com> Organization: home User-Agent: tin/1.8.1-20060215 ("Mealasta") (UNIX) (CYGWIN_NT-5.1/1.5.19(0.150/4/2) (i686)) Message-ID: <%nn8g.29165$_k2.508499@news2.nokia.com> Date: Wed, 10 May 2006 15:10:51 GMT NNTP-Posting-Host: 172.26.210.110 X-Complaints-To: newsmaster@nokia.com X-Trace: news2.nokia.com 1147273851 172.26.210.110 (Wed, 10 May 2006 18:10:51 EET DST) NNTP-Posting-Date: Wed, 10 May 2006 18:10:51 EET DST Xref: g2news2.google.com comp.lang.ada:4178 Date: 2006-05-10T15:10:51+00:00 List-Id: Ludovic Brenta wrote: > rick H wrote : >> Thanks, Ludovic. Bearing in mind that, in my original example, Var_A is >> declared as an *access* to the class-wide type, I tried declaring the >> various Put procedures as you showed, and then simply dereferencing >> Var_A when calling Put: >> Put (Var_A.all); >> However, the compiler (gnat) complained that I cannot use a class-wide >> argument in this case. > > This sounds suspicious; it should work. Could you post your full source > code? I think there may be a small mistake somewhere. > with Ada.Integer_Text_IO; with Ada.Float_Text_IO; procedure Simple_Case is type General_T is tagged null record; type Access_T is access General_T'Class; type Type_A is new General_T with record Data : Integer; end record; type Type_B is new General_T with record Data : Float; end record; procedure Put (Item: in General_T) is begin null; end Put; procedure Put (Item: in Type_A) is begin Ada.Integer_Text_IO.Put (Item.Data); end Put; procedure Put (Item: in Type_B) is begin Ada.Float_Text_IO.Put (Item.Data); end Put; Var_A : Access_T; -- could be "new Type_A" or a "new Type_B" begin -- Var_A := new Type_A' (Data => 100); Var_A := new Type_B' (Data => 100.0); Put (Var_A.all); end Simple_Case;