0

I am making a clinic and I need to make a object that stores two medicines at once. The interaction object means MEDICATION_1 is interacting with MEDICATION_2

However the following code is not correct because it does not meet the generic parameter

ERROR: VICG: Actual generic parameter does not conform to constraint.

code:

interaction: HASH_TABLE[MEDICATION, MEDICATION] 
geforce
  • 61
  • 6

1 Answers1

1

HASH_TABLE allows associating objects of one type with objects of another (or the same) type. The first parameter to HASH_TABLE is a value and the second one is a key. Therefore one can keep at most one value for the same key. If this suits your needs, the type of keys has to be HASHABLE. This type defines a function hash_code that computes an integer value for an object. All basic types and STRING are HASHABLE, so you can rely on the existing implementations to compute hash_code for MEDICATION objects. For example, if a medication has a unique name, it makes sense to define is as follows:

class MEDICATION inherit HASHABLE ... feature ...
   name: STRING
   ...
   hash_code: INTEGER
      do
         Result := name.hash_code
      end
end
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35