Inheritance 如何从Eiffel中的哈希表继承?

Inheritance 如何从Eiffel中的哈希表继承?,inheritance,eiffel,Inheritance,Eiffel,我想创建一个HASH_表的派生类,它实现了一些附加功能。我试着这样实现它: class HASH_TABLE2[G->HASHABLE] inherit HASH_TABLE[G,G] rename make as make_2 end create make feature make (capacity_ : INTEGER) do make_2(capacity_)

我想创建一个HASH_表的派生类,它实现了一些附加功能。我试着这样实现它:

class HASH_TABLE2[G->HASHABLE]
inherit
    HASH_TABLE[G,G]
        rename
            make as make_2
        end
create
    make
feature
    make (capacity_ : INTEGER)
        do
            make_2(capacity_)
        end
end
我得到这个错误:

Error: Creation instruction uses call to improper feature.

Feature name: make_2 (n: INTEGER_32)
Line: 1156
      do
->      create Result.make (n)
        if object_comparison then

我不明白为什么。如果我对inherit ARRAY[G]也这样做,那么它就可以正常工作。

问题是,功能
empty\u duplicate
(在错误消息中提到)使用原始创建过程
make
创建哈希表的新实例。但是,此功能不再是
HASH_TABLE2
中的创建过程。解决方案是相应地重新定义
empty\u duplicate

class HASH_TABLE2 [G -> HASHABLE]

inherit
    HASH_TABLE [G, G]
        rename
            make as make_2
        redefine
            empty_duplicate
        end

create
    make

feature
    
    make (capacity_: INTEGER)
        do
            make_2 (capacity_)
        end

feature {NONE} -- Duplication

    empty_duplicate (n: INTEGER_32): like Current
            -- <Precursor>
        do
            create Result.make (n)
            if object_comparison then
                Result.compare_objects
            end
        end

end

问题在于功能
empty\u duplicate
(在错误消息中提到)使用原始创建过程
make
创建哈希表的新实例。但是,此功能不再是
HASH_TABLE2
中的创建过程。解决方案是相应地重新定义
empty\u duplicate

class HASH_TABLE2 [G -> HASHABLE]

inherit
    HASH_TABLE [G, G]
        rename
            make as make_2
        redefine
            empty_duplicate
        end

create
    make

feature
    
    make (capacity_: INTEGER)
        do
            make_2 (capacity_)
        end

feature {NONE} -- Duplication

    empty_duplicate (n: INTEGER_32): like Current
            -- <Precursor>
        do
            create Result.make (n)
            if object_comparison then
                Result.compare_objects
            end
        end

end

如果不使用
preducer
重新定义
而不使用
重命名
会不会更优雅?@U.Windl然而,最初的问题明确指出创建过程已重命名,另一个过程用作创建过程(例如,如果创建过程有一些其他参数,而MWE中没有显示,则可能需要该参数)。如果不使用
preducer
重命名
重新定义
会不会更优雅?@U.Windl然而,最初的问题明确指出创建过程被重命名,而另一个过程被用作创建过程(例如,如果创建过程有一些其他参数,而MWE中没有显示,则可能需要该参数)。