【发布时间】:2018-01-20 18:16:48
【问题描述】:
我目前正在大学的实时编程语言课程中学习 Ada,并且有一个关于泛型的问题。
我有一个通用程序csv_put
package PSU_Logging is
type logged_signal_names_t is (
t,
U_V1,
I_L1,
U_C1,
I_L2,
U_C2,
I_Load
);
private
... Some types, tasks and subprogramms ...
generic
type Item_Type_t is private;
procedure csv_put (File : in File_Type; Item : in Item_Type_t);
end PSU_Logging;
有定义
package body PSU_Logging is
procedure csv_put (File : in File_Type; Item : in Item_Type_t) is
begin
Put (File, Item_Type_t'Image (Item));
Put (File, ", ");
end csv_put;
procedure csv_put_float is new csv_put (Item_Type_t => Float);
procedure csv_put_duration is new csv_put (Item_Type_t => Duration);
procedure csv_put_signal_name is new csv_put (Item_Type_t => logged_signal_names_t);
... Definition of other things ...
end PSU_Logging;
到目前为止一切顺利。太糟糕了,我在编译过程中收到以下错误
Compile
[Ada] psu_logging.adb
psu_logging.adb:9:18: prefix of "image" attribute must be a scalar type or a scalar object name
gprbuild: *** compilation phase failed
有什么想法吗?我想我可以像任何其他类型一样在泛型过程中使用泛型类型。由于我的所有实例都使用标量类型,我认为这应该不是问题。
顺便说一句:您最喜欢的 Ada 教程/参考资料是什么?我喜欢 Ada 上的 Wikibooks 页面,但它还没有完成。
【问题讨论】:
-
相关:stackoverflow.com/questions/13417337/… Ada 似乎没有办法将“任何标量类型”指定给泛型。 “任何 DISCRETE 类型……是的……
type Item_Type_t is (<>);,但对于固定类型和浮动类型,您只能自己处理。