我有一个面向对象的设计如下(Ada 2012)。 问题不在于设计本身,而在于特定运行时配置文件的后果。
-- several packages ommitted here, ads/adb mixed together
type Interface_A is interface;
type Interface_A_Class_Access is access all Interface_A'Class;
type Interface_B is interface and Interface_A;
type Interface_B_Class_Access is access all Interface_B'Class;
type Interface_C is interface and Interface_B
type Interface_C_Class_Access is access all Interface_C'Class;
type B_Impl is abstract tagged ...;
type B_Impl_Access is access all B_Impl;
type C_Impl is new B_Impl and Interface_C ...;
type C_Impl_Access is access all C_Impl;
function Create_C return C_Impl_Access is begin
return new C_Impl'(...);
end Create;
我有一个工厂来实例化Interface_A,Interface_B或Interface_C的对象。
package body My_Factory is
procedure Create_A return Interface_A_Class_Access is begin
return Create_A_Impl; -- error: dynamic interface conversion not supported by configuration
end Create_B;
procedure Create_B return Interface_B_Class_Access is begin
return Create_C_Impl; -- error: dynamic interface conversion not supported by configuration
end Create_B;
procedure Create_C return Interface_C_Class_Access is begin
return Create_C_Impl; -- error: dynamic interface conversion not supported by configuration
end Create_C;
end package My_Factory;
使用我的开关,我为两个工厂创建功能都收到以下错误:
error: dynamic interface conversion not supported by configuration
环境:
到目前为止我尝试了什么:
样品:
package body My_Factory is
...
procedure Create_B return Interface_B_Class_Access is begin
return Interface_B_Class_Access(Create_C); -- error: dynamic interface conversion not supported by configuration
end Create_B;
procedure Create_C return Interface_C_Class_Access is
tmp : Interface_C_Class_Access;
begin
tmp := Create_C; -- error: dynamic interface conversion not supported by configuration
return tmp;
end Create_C;
end package My_Factory;
同样的问题。
样品:
function Create_C return Interface_A_Class_Access is begin
return new C_Impl'(...); -- error: dynamic interface conversion not supported by configuration
end Create;
function Create_C return Interface_B_Class_Access is
tmp : Interface_B_Class_Access;
begin
tmp := new C_Impl'(...); -- works fine
return tmp;
end Create;
function Create_C return Interface_C_Class_Access is
tmp : Interface_B_Class_Access;
begin
tmp := new C_Impl'(...); -- works fine
return tmp;
end Create;
第二种选择正常。
我的问题:
我的第二个选择是否可以接受?为什么会有效?
我错过了什么吗?我知道这与编译器生成的代码管理调度表有一定关系,但我并没有真正得到深层机制/原因。
答案 0 :(得分:2)
"配置不支持"消息提示这是运行时的限制。并且您正在使用零占用(ZFP)运行时,例如,当涉及到不确定类型(如类范围类型和无约束数组)时,它具有严重的限制。
运行时文档应提供有关这些限制/限制的更多信息。