koko4nut
koko4nut

Reputation: 23

Array of unconstrained mutable type in Ada

I am trying to make an array of unconstrained mutable type elements; but, as the element is unconstrained, I get this error: "unconstrained element type in array declaration".

Here is my square type declaration :

type C_square(size : bRange) is tagged record

private

type C_square(size : bRange) is tagged record
  bConstaint : uint8 := size; 
  coord : T_coord;            
  color : e_color := unknown; 
end record;

And here comes the error:

type C_board(size : bRange) is tagged limited private; 

type square_matrix is array (uint8 range <>, uint8 range <>) of C_square; -- here is the problem C_square is unconstrained

private
type C_board(size : bRange := MIN_SIZE) is tagged limited record
  bSize    : uint8 := size;
  square_m : square_matrix(1..size, 1..size);
end record;

Is there any solution that allow me to have an array of unconstrained mutable elements?

Upvotes: 2

Views: 1132

Answers (1)

Jacob Sparre Andersen
Jacob Sparre Andersen

Reputation: 6601

You can't have an array of unconstrained elements.

Some alternatives:

  • Use an indefinite vector. (Good!)
  • Create an array of access to your indefinite type. (Bad!)

Upvotes: 3

Related Questions