OOP Query

BlitzMax Forums/BlitzMax Beginners Area/OOP Query

Ant(Posted 2005) [#1]
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




taxlerendiosk(Posted 2005) [#2]
Sure, you can have a field in TSecond that points to the same TList that the "parent" TFirst does.


Ant(Posted 2005) [#3]
Sorry, how would I go about that?


degac(Posted 2005) [#4]
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.


Ant(Posted 2005) [#5]
ok thanks guys, much appreciated


FlameDuck(Posted 2005) [#6]
Or is doing this a sign that I havent structured my code properly?
Bingo!