2016-11-26 77 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!)