jrd wrote
Why does the book specify that the construction of a new Array should be done with the "function" program component and the following syntax:
function Array new(int size)
... Is it somehow because Arrays have no field variables of their own and therefore no need to set those as part of object creation?
Yes, that is exactly the case.
A
constructor automatically allocates the correct sized memory block to hold the object's
fields, so a
constructor for Array would not allocate any storage to hold the Array elements.
By using a
function masquerading as a constructor, Array can allocate the required variable sized memory block.
--Mark