I want to make a derived class of HASH_TABLE which implements a few additional features. I tried implementing it like this:
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
I get this error:
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
I don't understand why. If I do the same with inherit ARRAY[G], then it works fine.
The issue is that the feature
empty_duplicate(mentioned in the error message) creates a new instance of a hash table using the original creation proceduremake. However, this feature is no longer a creation procedure inHASH_TABLE2. The solution is to redefineempty_duplicateaccordingly:Note that although the body of
empty_duplicateredeclaration looks identical to the original one, it callsmakefromHASH_TABLE2that has nothing to do withmakefromHASH_TABLEbecause the latter was renamed intomake_2.This brings us to the question whether
makefromHASH_TABLEcould remain the creation procedure inHASH_TABLE2. Unless the given example is a simplification, this is feasible and compiles without an issue: