Object Help

BlitzMax Forums/BlitzMax Programming/Object Help

rdodson41(Posted 2005) [#1]
Im making a stack-like data structure, and i have a problem. I pass in an Integer with my Push function, but value:Object is null. Try running this.
Type stack
	Field head:block
	
	Method Push(value:Object)		
		b:block=New block
		b.value=value
		b.fore=head
		head=b
	EndMethod

	Method Pop:Object()
		If _head=Null Then Return Null
		b:block=head
		head=head.fore
		value:Object=b.value
		Release b
		Return value
	EndMethod		
EndType

Type block
	Field value:Object
	Field fore:block
EndType



Function CreateStack:stack()
	s:stack=New stack
	s.head=Null
	Return s
EndFunction




'*****'
stk:stack=CreateStack()
stk.push(3)
stk.push(2)
stk.push(1)


Print String(stk.pop())
Print String(stk.pop())
Print String(stk.pop())
Print String(stk.pop())


All I get are nulls, and I traced it back to my Push function. The parameter value:Object goes null when Ints are passed in. Is there anything I'm doing wrong? Plus, I looked at the code fore linked lists, and they do the same sort of thing, but they work fine.


rdodson41(Posted 2005) [#2]
Ive simplified my problem down to this:
Function push(value:Object)
	Print String(value)
EndFunction

push(1)
push(2)
push(3)
push("asdf")
push("ffff")

I get a result of:



asdf
ffff

I just dont get why an object can be a string but not an integer.


rdodson41(Posted 2005) [#3]
It this doesn't work it needs to be fixed.


Brucey(Posted 2005) [#4]
I guess it means you can't cast an integer to a string.

Probably what this function is for - FromInt:String( value:Int )

...returning a String representation of an Int


Floyd(Posted 2005) [#5]
Why should an ordinary number, like 3, be an Object.

I'm surprised stk.push(3) is allowed, with 3 evidently cast to an Object. But, given that it is allowed, the Null result makes sense. What else could it be?


rdodson41(Posted 2005) [#6]
I don't know, I thought that since Int was a type, that it could be considered an object.