fb:porticula NoPaste
Virtuelle Funktionen in fb 0.24 ... 1. keine virtuellen Funktionen
Uploader: | kawe |
Datum/Zeit: | 14.11.2012 16:12:55 |
'--- base type, declaring a non-virtual destructor and a non-virtual sub "foo" ---
Type Upper Extends Object
Public:
Declare Sub novirt
Declare Destructor()
Protected:
Declare Constructor()
Declare Sub foo
End Type
Constructor Upper()
Print "called Upper::Constructor()"
'do something
End Constructor
Destructor Upper()
Print "called Upper::Destructor()"
'do something
End Destructor
Sub Upper.novirt
Print "called Upper::novirt()"
'do something
foo()
End Sub
Sub Upper.foo
Print "called Upper::foo()"
'do something
End Sub
'--- derived type, "overwriting" non-virtual destructor and sub "foo" ---
Type Middle Extends Upper
Public:
Declare Constructor()
Declare Sub other_novirt()
Declare Destructor()
Declare Sub foo
End Type
Constructor Middle()
Print "called Middle::Constructor()"
'do something
End Constructor
Sub Middle.other_novirt
Print "called Middle::other_novirt()"
'do something
End Sub
Destructor Middle()
Print "called Middle::Destructor()"
'do something
Base.Destructor()
End Destructor
Sub Middle.foo
Print "called Middle::foo()"
'do something
Base.foo()
This.other_novirt()
End Sub
Type Lower Extends Middle
Public:
Declare Constructor()
Declare Sub other_novirt()
Declare Destructor()
Declare Sub foo
End Type
'--- next derived type "Lower" ---
Constructor Lower()
Print "called Lower::Constructor()"
'do something
End Constructor
Sub Lower.other_novirt
Print "called Lower::other_novirt()"
'do something
base.other_novirt()
End Sub
Destructor Lower()
Print "called Lower::Destructor()"
'do something
base.destructor()
End Destructor
Sub Lower.foo()
Print "called Lower::foo()"
'do something
Base.foo()
End Sub
'--- demonstrate non-virtual (inadequate) sub and destructor calls
Dim As Upper Ptr m,l
m = New Middle()
Print"---"
m->novirt()
Print"---"
Delete m
Print "---"
l = New Lower()
Print"***"
l->novirt()
Print"***"
Delete l
Sleep