Greetings Puppies,
I'm new to this oop stuff and need a little guidance, and couldn't find the answer elsewhere. Please see code below:
On compilation it tells me it is 'unable to convert from parenttype to Yaxis'. I understand in one respect, ie, because 'Create()' is trying to return an object of parenttype not YAxis, but I thought the point of inheritance was that it would allow this sort of behaviour. I can't even seem to cast it.
Any suggestions?
Peace,
Jes
I'm new to this oop stuff and need a little guidance, and couldn't find the answer elsewhere. Please see code below:
Strict Graphics 800,600,0 Type ParentType Field id Field x#,y# Field xdir#, ydir# Field name$ Function Create:ParentType(newname$) Local temp:ParentType = New ParentType temp.x = Rnd(800) temp.y = Rnd(600) temp.name$ = newname$ Local n n = Rand(2) If n=1 Then temp.xdir = 1 Else temp.xdir = -1 End If n = Rand(2) If n=1 Then temp.ydir = 1 Else temp.ydir = -1 End If Return temp End Function Method Move() x:+xdir y:+ydir If x<0 Or x>800 Then xdir:*-1 If y<0 Or y>600 Then ydir:*-1 End Method End Type Type YAxis Extends ParentType Method Move() y:+ydir If y<0 Or y>600 Then ydir:*-1 End Method End Type Local y_axis:YAxis = YAxis.Create("Y Only : " + Rand(100)) Local myinstance:ParentType = ParentType.Create("X and Y : " + Rand(100)) While Not KeyDown(key_escape) Cls myinstance.move DrawText myinstance.name, myinstance.x, myinstance.y Flip Wend End
On compilation it tells me it is 'unable to convert from parenttype to Yaxis'. I understand in one respect, ie, because 'Create()' is trying to return an object of parenttype not YAxis, but I thought the point of inheritance was that it would allow this sort of behaviour. I can't even seem to cast it.
Any suggestions?
Peace,
Jes