Help

BlitzMax Forums/BlitzMax Beginners Area/Help

Scott Williams(Posted 2005) [#1]
I'm having a few problems with the docs.

Could someone please tell me where in the docs it shows you how to call the abstract member methods of derived types through the base type.

Cheers. Scott.


Scott Shaver(Posted 2005) [#2]
Type foo
	Method bar() Abstract
	Method doit()
		bar()
	EndMethod
End Type

Type foo2 Extends foo
	Method bar()
		Print "hello"
	End Method
End Type

Local a:foo2 = New foo2
a.bar()


I assume this is what you meant since base types wouldn't know anything about derived type specific methods.


Scott Williams(Posted 2005) [#3]
No. I actually meant this ...

' Main.bmx

Strict

Global TestAlien:Alien
Global TestCar:Car

Global MyList:TList
MyList = CreateList()

' the base object
Type BaseObject

Field Active:Int = False ' Is the object active ( alive )
Field x:Float = 0.0 ' x position
Field y:Float = 0.0 ' y psoition

Method Setup() Abstract

Method Info()
Print Active
Print x
Print y
End Method

End Type


' A derived object
Type Alien Extends BaseObject

Field Colour:String = "Red"

Method Setup()
Active = True
x = 10
y = 100
Colour = "Green"
End Method

Method Info()
Super.Info()
Print Colour
End Method

End Type

' Another derived Object
Type Car Extends BaseObject

Field CarType:String = "lorry"

Method Setup()
Active = True
x = 1000000
y = 1000000
CarType = "Boat"
End Method

Method Info()
Super.Info()
Print CarType
End Method

End Type

TestAlien:Alien = New Alien
TestCar:Car = New Car

MyList.AddLast(TestAlien)
MyList.AddLast(TestCar)

For Local TempObject:BaseObject = EachIn MyList
TempObject.Setup()
TempObject.Info()
Next


... I just couldnt find some of this stuff in the docs.

Cheers anyway.


Scott Shaver(Posted 2005) [#4]
ah, so how to call the base class from the derived class. Help/Language/User defined types and Help/modules/blitz runtime/abstract and Help/modules/blitz runtime/super

looks like you got it but there you go :)