somePointer[n]

BlitzMax Forums/BlitzMax Programming/somePointer[n]

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

What is the difference between somePointer[0] and somePointer[1]?

here is an example that doesnt perform properly when somePointer[0] is used within an object, but works properly when outside of the object. Look at the comment inside the object and change the [0] to [1] and it works. Why?

Strict


Type TGem 
	Field id:Int 				
EndType 


Type TQue
	Global gemPtrList:TList 
	
	
	Method addPtr(n:TGem)
			If gemPtrList = Null Then gemPtrList = New TList 
			Local p:TGemPtrList = New TGemPtrList 
			p.gemPtr = Varptr n
			gemPtrList.AddLast p 	
	End Method
	
	Method showQue()
			For Local n:TGemPtrList = EachIn gemPtrList
				'******************************************************
				'******* change n.gemPtr[0] to n.gemPtr[1] and it works
				Print n.gemPtr[0].toString() 
			Next	
	End Method
	
EndType 

Type TGemPtrList
	Field gemPtr:TGem Ptr 
EndType 
 

Global gem:TGem
Global que:TQue 

For Local i = 0 To 10
	 gem:TGem =New TGem
	 gem.id = i
	que:TQue = New TQue 
	que.addPtr(gem)
Next 
	Print "----------------outside loop"
	For Local n:TGemPtrList = EachIn que.gemPtrList
				
				Print n.gemPtr[0].toString()
	Next
	Print "----------------inside loop"		
	que.showQue()