2017-04-13 59 views
2

此代码有什么问题?编译器说有两件事情,即没有运行条目,并且运行接受不匹配条目(两者似乎都是错误的),并且单独指出在声明之前不能使用Train(但它已被声明)。请向我解释发生了什么事。Ada对象“火车”在声明结束前不能使用

我很犹豫要显示整个代码,但可以这样做。

type ItineraryType is array (0..255) of Integer; 
type Train is record 
    Label : Integer; 
    Capacity : Integer; 
    Maxspeed : Integer; 
    Starts : Integer; 
    Itinerary : ItineraryType; 
    Stops : Integer; 
    lock : access Mutex; 
end record; 

task type TrainThread is 
    entry Run (train1:Train); 
end; 
task body TrainThread is 
    train : Train; 
begin 
    accept Run (train1:Train) do 
     train := train1; 
    end; 
end; 

-- part of main 
train1 := new TrainThread; 
train1.Run(trains(i)); 

main.adb:51:05: warning: no accept for entry "Run" 
main.adb:52:17: object "Train" cannot be used before end of its declaration 
main.adb:54:09: no entry declaration matches accept statement 
gnatmake: "main.adb" compilation error 

回答

5

阿达是不区分大小写,所以trainTrain是等价的。所以声明train : Train将始终无效。 (不可否认,在这种情况下,gnat的信息会更好)