我想要一个包含标记记录类型的地图容器,所以我编写了这个程序,但 GNAT 编译器没有编译它:
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