什么是“在此上下文中需要的子类型标记”?究竟? [英] What is "Subtype mark required in this context" exactly?

查看:111
本文介绍了什么是“在此上下文中需要的子类型标记”?究竟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此情况下,我在(*)处获得了子类型标记。子类型mask到底是什么,为什么在这里抱怨?

I get Subtype mark required in this context at (*). What exactly is subtype mask and why is it complaining here?

main.adb

(*)Open_Route : Route(1..3) := (others => new Location(X=>1.0,Y=>1.0, id=>1));
--     Closed_Route : Route (Open_Route'First .. Open_Route'Last + 1);
--     P1 : Population (1..2);

Location.ads软件包规范

Location.ads package spec

    type Location is record
      Id : Positive;
      X : Float;
      Y : Float;
   end record;
   type Location_Acess is access all Location; 
   type Route is array (Positive range<>) of Location_Acess; 
   type Route_Acess is access all Route;
   type Population is array (Positive range<>) of Route_Acess;


推荐答案

subtype_mark 基本上是表示类型或子类型的名称( ARM 3.2.2(4))。 ARM始终使用 subtype_mark 的原因与某些不可思议的区别有关( ARM 3.2.1 );当您说 type Foo是时,您同时声明了一个类型及其 first子类型,并声明了 Foo 指的是第一个子类型。

A subtype_mark is basically a name that denotes a type or subtype (ARM 3.2.2(4)). The reason why the ARM uses subtype_mark throughout is to do with some arcane distinction (ARM 3.2.1); when you say type Foo is you are declaring both a type and its first subtype, and the name Foo refers to the first subtype.

我认为您的问题是您有一个包裹 Location 包含相同名称的实体,这使编译器感到困惑。

I think your problem is that you have a package Location containing an entity of the same name, and that this has confused the compiler.

您尚未提供完整的可编译代码示例,但请阅读在应用@ajb的建议后,我认为这将是这样:

You haven’t supplied a complete compilable code example, but reading between the lines I think it’d be something like this, after applying @ajb’s suggestion:

package Location is
   type Location is record
      Id : Positive;
      X : Float;
      Y : Float;
   end record;
   type Location_Acess is access all Location;
   type Route is array (Positive range<>) of Location_Acess;
   type Route_Acess is access all Route;
   type Population is array (Positive range<>) of Route_Acess;
end Location;



with Location; use Location;
package Location_User is
   Open_Route : Route(1..3) := (others => new Location'(X=>1.0,Y=>1.0, id=>1));
end Location_User;

,编译器错误消息将是

location_user.ads:3:47: subtype mark required in this context
location_user.ads:3:47: found "Location" declared at location.ads:1

(请参阅如何告诉您查看 location.ads ,包名称?)

(see how it’s telling you to look at line 1 of location.ads, the package name?)

您可以说 new Location.Location ,但您需要在任何地方说出来。

You could work round this by saying new Location.Location, but then you’d need to say it everywhere.

有两种规范的解决方案,并且支持者之间存在宗教分歧两个营地。

There are two canonical solutions, and there is a religious divide between the supporters of the two camps.

第一个(我的首选)是将包裹称为 Locations 并保留类型位置路线人口原样。

The first (my preferred one) would be to call the package Locations and leave the types Location, Route, Population as they are.

第二个( I 认为很丑,并且仅在迫切需要时使用)是用后缀修饰类型名称:

The second (which I consider ugly and would only use in dire need) would be to decorate type names with a suffix:

type Location_Type is

type Location_T is

这篇关于什么是“在此上下文中需要的子类型标记”?究竟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆