OO Inheritance Question

BlitzMax Forums/BlitzMax Beginners Area/OO Inheritance Question

jhans0n(Posted 2006) [#1]
Maybe I'm missing something here, but why doesn't this work? -
Type tMap
	Field height:Int
	Field width:Int
	
	Function Create:tMap(width:Int, height:Int)
		Local tempMap:tMap = New tMap
		tempMap.width=width
		tempMap.height=height
		Return tempMap
	EndFunction
EndType

Type tMapLarge Extends tMap
	Field tiles:Int [100,100]
EndType


Global map:tMapLarge = tMapLarge.Create(20,20)


Since tMapLarge extends tMap, shouldn't the Create function be inherited? Instead I get a compile error stating that it's unable to convert from tMap to tMapLarge. Do I need to override the Create function for the derived type?


Perturbatio(Posted 2006) [#2]
The inherited create function is creating a type TMap, not TMapLarge.

You *could* cast it, but you're probably better off writing a TMapLarge create function.


jhans0n(Posted 2006) [#3]
Cool. Thanks for the quick reply!