4 ms·
Delphi/Pascal has 2-layered constructors. There is a virtual class method to allocate memory and a so called constructor that initializes fields that should be
by benibela 5y ago
Delphi/Pascal has 2-layered constructors.
There is a virtual class method to allocate memory and a so called constructor that initializes fields that should be zero.
The user of a class, only calls the constructor. The constructor then calls the memory-allocation method implicitly (you can see the call with a disassembler, but not in the Pascal code).
Anyways, you can override the memory-allocation method for each class. E.g. a useful case would be to build an arena allocator just for that class. But you can also override it, so that calling the class constructor returns a null