Ada中的编译器放弃了Generic类型的包实例化

时间:2013-01-30 10:57:56

标签: instantiation ada

好的,所以我尝试运行调用包dirforinv.adb的代码:

WITH  Text_IO;
WITH  Ada.Numerics.Generic_Real_Arrays;
WITH  Ada.Numerics.Generic_Elementary_functions;
WITH  Ada.Strings.Fixed;
WITH  dirforinv;
PROCEDURE  levfordir  IS

J : CONSTANT  Integer := 100;

TYPE  Real  IS DIGITS  13;

PACKAGE  Real_IO  IS NEW  Text_IO.Float_IO   (Real);
PACKAGE  Int_IO   IS NEW  Text_IO.Integer_IO (Integer);

TYPE  Gen_arr  IS ARRAY (INTEGER RANGE <>, INTEGER RANGE <>)  OF  Real;
TYPE  var_array  IS ARRAY (INTEGER RANGE <>)  OF  Real;

PACKAGE  Real_arrays  IS NEW Ada.numerics.Generic_Real_Arrays (Real);
USE      Real_arrays;
PACKAGE  sdirect      IS NEW dirforinv (var_array, Gen_arr);
PACKAGE  Math         IS NEW Ada.numerics.Generic_Elementary_functions (Real);
USE      Math;

但我收到以下错误。

  PACKAGE  sdirect      IS NEW dirforinv (var_array, Gen_arr);
                                             |
    >>> expect float type in instantiation of "Real"
    >>> instantiation abandoned

我不明白这一点,因为dirforinv需要5个数组,1个var_array和4个Gen_arr。 dirforinv的.ads在下面。

WITH Profiles,
   Profiles.Inputs,
   Profiles.Conversion,
   Profiles.Provide_Grids,
   Profiles.Multipolar,
   Profiles.Unno_Solver,
   Profiles.Outputs,
   Text_IO, Ada.Numerics.Generic_Elementary_Functions;
USE Profiles;


GENERIC
  TYPE Real  IS DIGITS <>;
  TYPE Gen_arr  IS ARRAY (INTEGER RANGE <>, INTEGER RANGE <>) OF REAL;
  TYPE var_array  IS ARRAY (INTEGER RANGE <>)  OF  REAL;

PACKAGE dirforinv IS

 PROCEDURE direct (Variables                 : IN  var_array;
                   StoI, StoQ, StoU, StoV    : OUT Gen_arr );

END dirforinv;

感谢您的任何建议。

1 个答案:

答案 0 :(得分:6)

dirforinv的声明(顺便说一句可怕的名字)是

GENERIC
  TYPE Real  IS DIGITS <>;
  TYPE Gen_arr  IS ARRAY (INTEGER RANGE <>, INTEGER RANGE <>) OF REAL;
  TYPE var_array  IS ARRAY (INTEGER RANGE <>)  OF  REAL;

PACKAGE dirforinv IS

有三个通用的形式参数;您尝试的实例化是

PACKAGE  sdirect      IS NEW dirforinv (var_array, Gen_arr);

只有两个。