我有一个包含普通规格和正文文件的主包.我正在尝试创建父包的子包,但希望它们在单独的编译文件中.如果它只是一个包体,或者它是一个子程序/ proc/func,我可以很容易地完成它.但是,我不能让它让我制作一个子规格文件.
我这样做的原因是因为我希望在同一父母的其他孩子可以使用的孩子中获得信息.我知道我可以通过在父代中包含spec部分来实现这一点,但这使得我的父文件非常大.
这甚至可能,或者我别无选择,只能制作另一个根单位?或者只是在父母身上留下一切明智的东西?
我试过了:
在父:(
package Child1 is separate; 也试过Parent.Child1,但这给编译错误
在孩子:
separate(Parent)
package Parent.Child1 is
....
end Parent.Child1;
Run Code Online (Sandbox Code Playgroud)
想法?只是不可能?
更新:我正在使用Green Hills Multi Compiler进行编译.Ada95语言版,非OO项目.
我正在尝试从许多月前做一些旧C++代码的基本翻译来学习Ada,我一直对如何使用内置Generic_Sorting对矢量进行排序感到困惑.我还没有找到任何具体的实际例子,最接近现在已经不复存在的丹麦维基文章看起来好像有一个完整的例子,但存档没有抓住它:https:// web.archive.org/web/20100222010428/http://wiki.ada-dk.org/index.php/Ada.Containers.Vectors#Vectors.Generic_Sorting
这是我认为应该从上面的链接工作的代码:
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Vectors; use Ada.Containers;
procedure Vectortest is
package IntegerVector is new Vectors
(Index_Type => Natural,
Element_Type => Integer);
package IVSorter is new Generic_Sorting;
IntVec : IntegerVector.Vector;
Cursor : IntegerVector.Cursor;
begin
IntVec.Append(3);
IntVec.Append(43);
IntVec.Append(34);
IntVec.Append(8);
IVSorter.Sort(Container => IntVec);
Cursor := IntegerVector.First(Input);
while IntegerVector.Has_Element(Cursor) loop
Put(IntegerVector.Element(Cursor));
IntegerVector.Next(Cursor);
end loop;
end Vectortest;
Run Code Online (Sandbox Code Playgroud)
我试过这么多不同的组合use和with,但所有我能得到的各种错误代码.上面的代码给出了Generic_Sorting is not visible,但是当我尝试明确说明with Ada.Containers.Vectors.Generic_Sorting我得到了错误"Ada.Containers.Vectors.Generic_Sorting" is not a predefined library …
我想String在Ada中初始化一个固定长度或多或少如下:
S : String (1..256) := ("Hello", others => Character'Val (0));
Run Code Online (Sandbox Code Playgroud)
我在尝试编译时遇到错误.有没有办法实现类似于上面的东西?
我正在尝试在Ada中进行基本的I/O,但是关于这个的文档不是很有用(除非我去错了地方).在下面的块中,我试图测试字符串追加和输出,但由于某种原因,它实际上只输出"Hello WORLD!" 我确定我错过了一些非常简单的东西,但我已经尝试了几个小时来弄明白这一点.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
procedure Main is
usrIn : String(1..80);
appendString : Unbounded_String;
last : Natural;
begin
Put_Line ("Hello WORLD!");
Get_Line(usrIn, last);
Put_Line ("AAAAAAAA");
appendString := To_Unbounded_String("USER IN: ");
Append(appendString,usrIn);
Put_Line("Output follows");
Put_Line(To_String(appendString));
end Main;
Run Code Online (Sandbox Code Playgroud) 我想使用Ada 95实现类似于接口的东西(因此典型的OO接口不可用).我通过在记录中使用泛型和一组"指向方法"来完成它.代码如下.
编辑:我知道它可以通过将子程序作为形式参数传递给泛型包来完成,但我想避免传递太多参数.
我认为必须有更好的方法来实现我想要的东西,所以我想如果我是对的,如果是的话,我想看一个代码的例子.
"接口"在名为的通用包中声明Drivers.在那里,有一条记录,其中包含表示驱动程序的泛型类型的变量和包含其操作的记录:
generic
type T is private;
type Error is private;
NOT_IMPLEMENTED_CODE : Error;
package Drivers is
type Driver is private;
-- Need to declare these types because I compile with Ada 95.
type ToStringPtr is access function(self : in T) return String;
type ReadLinePtr is access procedure(self : in T; buffer : out String; err : out Error);
type DriverOps is
record
to_string_op : ToStringPtr := null;
read_line_op : ReadLinePtr := null; …Run Code Online (Sandbox Code Playgroud)