Ada中无约束的可变类型的数组

时间:2016-11-26 22:10:29

标签: arrays types ada

我试图创建一个无约束的可变类型元素的数组;但是,由于元素是不受约束的,我得到这个错误:“数组声明中的无约束元素类型”。

这是我的方型声明:

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;

是否有任何解决方案允许我拥有一系列无约束的可变元素?

1 个答案:

答案 0 :(得分:3)

你不能拥有数组的无约束元素。

一些替代方案:

  • 使用不定矢量。 (良好!)
  • 创建一个对您的不定类型的访问数组。 (错误!)
相关问题