Paul Ishenin wrote:
David Emerson wrote:
d. What happens with inheritance?

d.1. wrt class constants and class vars-- are there separate "instances" (for lack of a better word) of these, one instance for each descendant? Or is the class var/const only stored once for the ancestor that declares it, and all descendants share that?
Class vars (static class fields) are stored only once for the class which declares them and all descendants share that.

Example:
TSomeClass = class
class var Value: Integer;
end;

TDescendant = class(TSomeClass);
begin
 TSomeClass.Value := 1;
 TDescendant.Value := 2;
 WriteLn(TSomeClass.Value); // this must output 2
end;

Class static field is not a new feature. But now you can declare them using 'class var' section after methods or 'type'/'const' section.

Can we have a virtual version too like described here
http://hallvards.blogspot.com/2007/05/hack17-virtual-class-variables-part-i.html


Marc

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to