我想有一个地图容器,其中将包含一个标签的记录类型,所以我写了这个程序,但GNAT编译器不会编译:为了使用多态性,可以在Ada中实例化一个带有标记记录类型的Map容器?
type http_response is tagged private;
package map_package is new Ada.Containers.Ordered_Maps
(Key_Type => Unbounded_String,
Element_Type => http_response);
我也有那些编译错误:
http.ads:47:04: instantiation error at a-coorma.ads:199
http.ads:47:04: premature use of type with private component
http.ads:47:105: premature use of private type
确实我想使用多态,因为我的地图将包含其他标记的记录类型,它从http_response类型继承。
如何改正这段代码?
如果我纠正这样的代码:
package map_package is new Ada.Containers.Ordered_Maps
(Key_Type => Unbounded_String,
Element_Type => http_response'Class);
我得到这样的错误:
http.ads:47:04: instantiation error at a-coorma.ads:195
http.ads:47:04: class-wide subtype with unknown discriminants in component declaration
http.ads:47:04: instantiation error at a-coorma.ads:199
http.ads:47:04: premature use of type with private component
http.ads:47:118: premature use of type with private component
http_request或http_response?声明和泛型参数不匹配。但是如果你想要多态性,我认为你需要类的类型:'Element_Type => http_response'class' –
@Brian Drummond:我的地图将conatin http_response,我刚刚做了一个复制粘贴错误。当我添加“'类”,我有这些错误:http.ads:47:04:实例化错误在a-coorma.ads:195 http.ads:47:04:在组件声明中具有未知区分的类的子类型 http.ads:47:04:实例化错误在a-coorma.ads:199 http.ads:47:04:过早使用类型与私人组件 http.ads:47:118:过早使用类型与私人组件 – backlash
请更新您的问题(a)更正复制粘贴错误,并(b)包含错误消息,格式化为代码以便于阅读。在您编辑时,您可能会在标题中将“ADA”更改为“Ada”;这不是一个缩写。欢迎来到Stack Overflow! –