[Oberon] Type compatibility of procedures
Srinivas Nayak
sinu.nayak2001 at gmail.com
Fri Nov 11 08:44:14 CET 2016
Dear All,
TYPE
Class = POINTER TO ClassDesc;
ClassDesc = RECORD
x : INTEGER;
method : PROCEDURE (self: Class; v : INTEGER);
END;
Subclass = POINTER TO SubclassDesc;
SubclassDesc = RECORD (ClassDesc)
y : INTEGER
END;
VAR
ptr : Class;
subPtr : SubClass;
If we have two procedures like this:
PROCEDURE Method (self: Class; v : INTEGER);
BEGIN
self.x := v
END Method;
PROCEDURE OverridingMethod (self: Subclass; v : INTEGER);
BEGIN
self.x := v;
self.y := v
END OverridingMethod;
We can do,
NEW(subPtr); subPtr.method := Method;
Can't we do,
NEW(subPtr); subPtr.method := OverridingMethod; ?
If no, is there any reason why we didn't make
these two procedure types compatible?
PROCEDURE Method (self: Class; v : INTEGER);
PROCEDURE OverridingMethod (self: Subclass; v : INTEGER);
With thanks and best regards,
Yours sincerely,
Srinivas Nayak
Home: http://www.mathmeth.com/sn/
Blog: http://srinivas-nayak.blogspot.in/
More information about the Oberon
mailing list