2016-11-26 78 views
1

我试图创建一个无约束的可变类型元素的数组;但是,因为元素没有受到训练,所以我有这个错误:“数组声明中的无约束元素类型”。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 uncontrained 

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; 

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

+2

您可能正在寻找[_indefinite container_](http://www.adaic.org/resources/add_content/standards/05rat/html/Rat-8-5.html)。 – trashgod

+0

也许给大小默认会有所作为? – Alex

回答

3

您不能有无约束元素的数组

一些替代方案:

  • 使用无限期的载体。 (好!)
  • 创建一个访问你的不确定类型的数组。 (Bad!)