Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: rdc on May 05, 2011

Title: Inheritance Branch
Post by: rdc on May 05, 2011
v1ctor has added inheritance to FB and you can get the branch from this (http://www.freebasic.net/forum/viewtopic.php?p=156572#156572) post on the FB forum. You will probably need to have the current official build installed before applying this. Back up your current installation before applying this though just to be safe.

I have been playing around with it, and it seems to work. Some examples are found in the examples\classes folder. Here is what the new syntax looks like from one of the examples:

Code: [Select]
type Foo
declare function DoSomething() as integer
declare function DoIt() as integer
declare function DoItFromBase() as integer

private:
dim unused as byte
end type

function Foo.DoSomething() as integer
return 1
end function

function Foo.DoIt() as integer
return DoSomething()
end function

function Foo.DoItFromBase() as integer
return DoSomething()
end function

type SuperFoo extends Foo
declare function DoSomething() as integer
declare function DoIt() as integer
end type

function SuperFoo.DoSomething() as integer
return 2
end function

function SuperFoo.DoIt() as integer
return DoSomething()
end function

sub main
dim as SuperFoo inst

assert( inst.DoIt() = 2 )
assert( cast( Foo, inst ).DoIt() = 1 )
assert( inst.DoItFromBase() = 1 )

print "all tests ok"
end sub

main

Notice the extends keyword here. In the above example, SuperFoo inherits from Foo.

I'll be beating on this some and post my findings.