我不知道,这是否叫做赛跑,但我想要一个HashMap(字符串,长,短,字符串);
侏儒编译器抱怨:
main.adb:20:13: warning: possible infinite recursion
main.adb:20:13: warning: Storage_Error may be raised at run time
main.adb:24:13: warning: possible infinite recursion
main.adb:24:13: warning: Storage_Error may be raised at run time在这里写"=“函数的正确方法是什么?
main.adb
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Strings.Hash;
with Ada.Text_IO;
procedure Main is
subtype Short is Short_Integer;
subtype Long is Long_Integer;
function Hash (X : String) return Ada.Containers.Hash_Type is
(Ada.Strings.Hash (X));
function Hash (X : Short) return Ada.Containers.Hash_Type is
(Ada.Containers.Hash_Type'Mod (X));
function Hash (X : Long) return Ada.Containers.Hash_Type is
(Ada.Containers.Hash_Type'Mod (X));
package Short_String_Map is new Ada.Containers.Indefinite_Hashed_Maps (Short, String, Hash, "=");
function "=" (Left, Right : Short_String_Map.Map) return Boolean is
(Left = Right);
package Long_Short_Map is new Ada.Containers.Indefinite_Hashed_Maps (Long, Short_String_Map.Map, Hash, "=");
function "=" (Left, Right : Long_Short_Map.Map) return Boolean is
(Left = Right);
package String_Long_Map is new Ada.Containers.Indefinite_Hashed_Maps (String, Long_Short_Map.Map, Hash, "=");
begin
-- Map(String, Long, Short, String);
null;
end Main;发布于 2014-03-12 14:58:03
而不是
function "=" (Left, Right : Short_String_Map.Map) return Boolean is
(Left = Right);写
function "=" (Left, Right : Short_String_Map.Map) return Boolean is
(Short_String_Map."=" (Left, Right));或者,更好的(我认为):
function "=" (Left, Right : Short_String_Map.Map) return Boolean
renames Short_String_Map."="; 问题是,您编写它的方式,= in Left = Right指的是您刚才根据可见性规则在上面的行上定义的"="。当然,这意味着您刚刚定义了一个无限递归函数。要使用在"="中定义的Short_String_Map,您必须使用像Short_String_Map."="(Left,Right)这样的语法来显式显示您所指的"="。
https://stackoverflow.com/questions/22349695
复制相似问题