Ada 中不受约束的可变类型数组

Array of unconstrained mutable type in Ada

我正在尝试制作一个不受约束的可变类型元素数组;但是,由于元素不受约束,我收到此错误:"unconstrained element type in array 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;

错误来了:

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;

是否有任何解决方案可以让我拥有一组不受约束的可变元素?

您不能拥有 数组 不受约束的元素。

一些备选方案:

  • 使用不定向量。 (好!)
  • 创建一个访问你的不确定类型的数组。 (不好!)