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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a0c:cd8e:: with SMTP id v14mr14416338qvm.182.1580087079854; Sun, 26 Jan 2020 17:04:39 -0800 (PST) X-Received: by 2002:a9d:6544:: with SMTP id q4mr11150155otl.194.1580087079555; Sun, 26 Jan 2020 17:04:39 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no2558199qtd.0!news-out.google.com!w29ni565qtc.0!nntp.google.com!g89no2558191qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 26 Jan 2020 17:04:39 -0800 (PST) In-Reply-To: <79386e8a-20cb-4bcb-a60a-531919ee6976@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: <79386e8a-20cb-4bcb-a60a-531919ee6976@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <46cfccd5-a4be-46a0-8fa0-c3b6842842ed@googlegroups.com> Subject: Re: Having problems instantiating a child class with an extension aggregate From: Jere Injection-Date: Mon, 27 Jan 2020 01:04:39 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57959 Date: 2020-01-26T17:04:39-08:00 List-Id: On Sunday, January 26, 2020 at 7:22:13 PM UTC-5, b.mcgui...@gmail.com wrote= : > I have three packages: >=20 > >=20 > I am trying to create instances of APL_Data_Array in apl_data_arrays.adb.= I have procedures that perform operations on one or two arrays and genera= te a third array with the same dimensions as one of the original arrays, so= I want to create a result array, copying the dimensions from an existing a= rray and allocating space for the array elements to be calculated. I tried= : >=20 > result : APL_Data_Array_Pointer :=3D new APL_Data_Array'( > g_shape =3D> new Dimensions'(right.g_shape.all), > g_data =3D> new Elements(right.g_data.all'Range) > ); >=20 >=20 > This gives me an error message: >=20 > apl_data_arrays.adb:180:36: type of aggregate has private ancestor "Contr= olled" > apl_data_arrays.adb:180:36: must use extension aggregate >=20 The Aggregate syntax would normally be: result : APL_Data_Array_Pointer :=3D new APL_Data_Array'( APL_Arrays.APL_Array(right) with -- This line changed! g_data =3D> new Elements(right.g_data.all'Range) );=20 BUT DO NOT DO THIS because g_shape is an access type and you almost certainly don't want to copy that directly, which is what it will do UNLESS you create an adjust procedure for it that correctly handles doing a deep copy of the pointed to object. >=20 > But when I try: >=20 > result : APL_Data_Array_Pointer :=3D new APL_Data_Array'( > APL_Array'(new Dimensions'(right.g_shape.all)) with > g_data =3D> new Elements(right.g_data.all'Range) > ); >=20 >=20 > I get another error message: >=20 > apl_data_arrays.adb:180:48: no selector "g_shape" for type "APL_Data_Arra= y" defined at apl_data_arrays.ads:46 >=20 > This puzzles me since g_shape is a member of the parent class and should = be visible to the child class. I don't see how to fix the problem. >=20 The g_shape parameter is "private", so it is not visible to the child class= =20 as is, however if you make APL_Data_Arrays a child package of APL_Arrays it can then see into the parent type: generic type Element is private; package APL_Arrays.APL_Data_Arrays is=20 -- all your stuff end APL_Arrays.APL_Data_Arrays; Child packages can see into the private sections of their parent packages. However my first comment can solve your problem directly if you add a=20 correct Adjust procedure for the APL_Array type.