comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using Access Types for a simple solution
Date: Mon, 25 Jul 2016 16:28:46 +0200
Date: 2016-07-25T16:28:46+02:00	[thread overview]
Message-ID: <nn57mv$n29$1@gioia.aioe.org> (raw)
In-Reply-To: 579615c5$0$20671$e4fe514c@news.kpn.nl

On 2016-07-25 15:35, ldries46 wrote:
> Let me first explain the problem. I do have a matrix of records
>
> type Box is record
>   ...
>   ...
> end record
>
> Grid : array( 1 .. N,  1 .. M) of Box;
>
> Now I must do something with a random set out of elements from the
> matrix. I would like to create an array of pointers to the elements of
> the matrix so that I can use these elements and file the changes
> directly if the array. So I created a type:
>
> type Box_Access is access all Box;
>
> and make an array
>
> Box_Array : array(1 .. Q) of Box_Acess;
>
> When try to use that in a simple statement
>
> Box_Array(n) := Grid(n1, n2)'Access;
>
> I get the error (only for this statement): prefix of 'Access attribute
> must be aliased.
>
> I tried:
>
> Grid : aliased array( 1 .. N,  1 .. M) of Box;
>
> But that also gives the same error.
> I cannot imagine that what I want is not possible in Ada as I can
> realise it in C++ so I do miss something.

Yes, the error message that tells you: "prefix of 'Access attribute must 
be aliased". The prefix of 'Access attribute in Grid(n1, n2)'Access is 
obviously Grid(n1, n2).

Aliased array /= array of aliased elements.

And you should not use pointers anyway. Do sets of array indices instead.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2016-07-25 14:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25 13:35 Using Access Types for a simple solution ldries46
2016-07-25 14:28 ` Dmitry A. Kazakov [this message]
2016-07-25 15:27 ` ldries46
2016-07-25 21:39   ` rieachus
2016-07-26 18:16 ` Aurele
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox