virtual constructor II



virtual_constructor 2
Smart pascal source code
type TClassA = class Field: String; constructor Create; virtual; end; type TClassB = class(TClassA) constructor Create; override; end; constructor TClassA.Create; begin Field := 'A'; end; constructor TClassB.Create; begin Field := 'B'; end; var o, o2: TClassA; o := TClassA.Create; WriteLn(o.Field); o2 := o.Create; WriteLn(o2.Field); o := TClassB.Create; WriteLn(o.Field); o2 := o.Create; WriteLn(o2.Field); {<<< RESULT - CONSOLE LOG >>> ----------------------------- Errors >>>> Warning: Constructor invoked on instance outside of constructor [line: 26, column: 7] Warning: Constructor invoked on instance outside of constructor [line: 31, column: 7] Result >>>> A A B B ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}