how to do a child class ?

New to FreeBASIC? Post your questions here.
bluatigro
Posts: 651
Joined: Apr 25, 2012 10:35
Location: netherlands

how to do a child class ?

Postby bluatigro » Apr 28, 2012 10:08

i do know how to do this in c++
but now in free basic :

Code: Select all

type ta
  dim i as intrger
  declare constructor()
  declare constructor( n as integer )
end type
constructor ta()
  this.i = 0
end constructor
constructor ta( n as integer )
  this.i = n
end constructor
type tb ''child of ta ?
  declare constructor()
  declare constructor( n as integer )
end type
constructor tb()
  ''ta() ?
end constructor
constructor tb( n as integer )
  ''ta( n ) ?
end constructor
''dim q as ta( 2 ) ?
fxm
Posts: 9637
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to do a child class ?

Postby fxm » Apr 28, 2012 14:13

Code: Select all

type ta
  dim i as integer
  declare constructor()
  declare constructor( byval n as integer )
end type
constructor ta()
  this.i = 0
end constructor
constructor ta( byval n as integer )
  this.i = n
end constructor
type tb extends ta
  declare constructor()
  declare constructor( byval n as integer )
end type
constructor tb()
  Base()
end constructor
constructor tb( byval n as integer )
  Base( n )
end constructor

dim q as tb = tb( 2 )
print q.i
sleep
Remark: you must use a recent-Git-Build of FreeBASIC:
topic: Where get a Recent-Git-Build of FreeBASIC?
download at: FreeBASIC-Portal.de
(fbc0.24_windows.zip or fbc0.24_linux.zip)

There are four new keywords linked to inheritance:
EXTENDS
BASE (member access)
OBJECT
IS (Run-time type information operator)
Last edited by fxm on Apr 28, 2012 15:51, edited 5 times in total.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: how to do a child class ?

Postby MOD » Apr 28, 2012 14:27

These links will be 404 in future, better link to FreeBASIC-Portal.
bluatigro
Posts: 651
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: how to do a child class ?

Postby bluatigro » Apr 29, 2012 17:21

thans for help

due to my eye problems i have difficultys whit searching
Veggiet
Posts: 156
Joined: Apr 17, 2006 19:41

Re: how to do a child class ?

Postby Veggiet » May 09, 2012 15:42

um devs? why is this in the documentation while the current main offered download is 0.23? I don't mean to complain but I've been trying to use the extends and getting a compile error, I thought I was doing something wrong. There should at least be a note on the FBwiki that this feature will be in 0.24 and above. Now for the time being I will go back to creating multiple casts arg...
fxm
Posts: 9637
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to do a child class ?

Postby fxm » May 09, 2012 16:36

Veggiet wrote:why is this in the documentation while the current main offered download is 0.23? I don't mean to complain but I've been trying to use the extends and getting a compile error, I thought I was doing something wrong.
Look at the page:
Download
There is coherence between the last official revision 'FreeBASIC 0.23.0' and the documentation 'FreeBASIC User Manual for 0.23.0'.

Veggiet wrote:There should at least be a note on the FBwiki that this feature will be in 0.24 and above.
And read the comment at:
FBWiki
This wiki contains the FreeBASIC Manual. The manual is updated whenever possible to document the latest version of FreeBASIC available. Some features documented here might not be available yet in the latest official FreeBASIC release, and may only be available when building the FreeBASIC compiler and/or runtime libraries from sources, or downloading a compiled development version. The content on this wiki is created and updated by users and developers of FreeBASIC.
Last edited by fxm on May 09, 2012 19:08, edited 1 time in total.
fxm
Posts: 9637
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to do a child class ?

Postby fxm » May 09, 2012 16:58

Veggiet wrote:Now for the time being I will go back to creating multiple casts arg...
You can get the last current version at FreeBASIC-Portal.de (Übergangslösung):
current version fbc0.24 at present time.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 6 guests