-
24-09-2019 - |
题
假设我有以下内容:
type blah is abstract tagged
record
element1 : integer;
end record;
type blah2 is abstract tagged
record
element2 : integer;
end record;
我希望这是可能的,我可以做这样的事情:
type blah3 is abstract new blah1 and blah 2 with null record;
因此,在理论上我现在可以访问blah3.element1和blah3.element2
这是可能的?和任何提示或提示?
更新:
,才有可能使用指针(含嗒嗒和blah2)?引用blah3的元素
即。 (这只是一个粗略的想法代码是可怕的...... LOL)
type blah3 is new type with
record
element1 : ptr to blah.element1;
element2 : ptr to blah2.element2;
end record
和然后能够通过被访问 blah3.element1例如?
解决方案
马克C是右(如常)。
直接多重继承是非常contraversial即使在支持它的语言。有什么编译器应该在一些边缘情况来做,比如当两个父类中定义不同版本的同一方法或成员的大问题。这是明确的不强>允许Ada95的,当他们加入继承。
所以,你的下一个问题将是“那么我怎么做我想做的事?”
这取决于你正在尝试使用多重继承来实现的。在最坏的(最复杂)的情况下,你通常可以achive你正在寻找“混入”继承的效果。我的的的这么做过,但我仍然认为这是这个AdaIC文章中解释最好:的 Ada95的和多重继承比我可以做我自己。
这里的一个摘要:
阿达95支持多继承 模块包容(经由多个 “与” /“使用”条款), 多重继承 “是实现-使用”通过私人 扩展和记录组合物,以及 通过多重继承混合插件 使用泛型,正规的套餐,并 访问判别。
看来,2005年的Ada有另一种更简单的方式来做到这一点(“接口”),但我还没有机会尝试呢。你可以阅读更多关于它(包括直接原因是心肌梗死的还是的考虑阿达坏)的此处。我发现了这个例子。同样,这只会如果你的编译工作支持2005年的Ada
Interfaces can be composed from other interfaces thus
type Int2 is interface;
...
type Int3 is interface and Int1;
...
type Int4 is interface and Int1 and Int2;
...
不隶属于 StackOverflow