OOP Query
BlitzMax Forums/BlitzMax Beginners Area/OOP Query| 
 | ||
| Hi, quick OOP question. If I create a Type TFirst which contains a list of TSeconds, is there any way in which I can get an instance of TSecond to access what is in the list 'list2' (defined and belonging to TFirst)? Or is doing this a sign that I havent structured my code properly? Thanks for any help | 
| 
 | ||
| Sure, you can have a field in TSecond that points to the same TList that the "parent" TFirst does. | 
| 
 | ||
| Sorry, how would I go about that? | 
| 
 | ||
| First you must declar list1 and list2 as NEW TLIST. Secondly to access the LIST2 you should write 
Type TFirst
	Field list:TList=New tlist
    Field list2:TList=New tlist   ' Its this list I want to access
	
	
	Function CreateSomething:TFirst()
	 	Local NewSomething: TFirst
	 	NewSomething=New TFirst
	
	 	For Local n=1 To 10
			
			'a:tsecond=New tsecond
		
	   		NewSomething.list2.Addlast(New tsecond)
	 	Next
		Return NewSomething
	EndFunction
	
End Type
Type TSecond
	   Field x:Int, y:Int
end Type
al:tfirst=Tfirst.createSomething()
Print String(al.list.count())
Print String(al.list2.count())
but I really don't understand what do you want exactly. | 
| 
 | ||
| ok thanks guys, much appreciated | 
| 
 | ||
|  Or is doing this a sign that I havent structured my code properly? Bingo! |