Hi,
I hope to maybe get some help with comparing polymorphed object types through a function call.
Please consider this pseudo code. 3 objects of derived types are created and stored in Base type pointer, then added to a list.
So the list is populated with 3 differend sub types all hiding under base type. What i really need is to implement some sort of method that will accept one of the derived types as argument, loop through the list, and return the same type object if found.
I can do this:
' but I need to encapsulate that loop into a method, and somehow return proper type, so I want to do this:
Any way of doing this? I am trying to implement a component based entity approach, and need method that will Return a component of an entity if it exists in the list.
TIA, and i hope this makes sense.
I hope to maybe get some help with comparing polymorphed object types through a function call.
Please consider this pseudo code. 3 objects of derived types are created and stored in Base type pointer, then added to a list.
Type TBase Type TA extends TBase Type TB extends TBase Type TC extends TBase a:TBase = new TA b:TBase = new TB c:TBase = new TC list.add(a) list.add(b) list.add(c)
So the list is populated with 3 differend sub types all hiding under base type. What i really need is to implement some sort of method that will accept one of the derived types as argument, loop through the list, and return the same type object if found.
I can do this:
' i want to check if a type exists in the list for o = eachin List if TA(o) ' object is of type TA if TB(o) ' object is of type TB if TC(o) ' object is of type TC next
' but I need to encapsulate that loop into a method, and somehow return proper type, so I want to do this:
o:TA = GetType(of type TA somehow) Method GetType:TBase( some type) for o = eachin List ' any way to pass a type and do a cast like this???? if some type(o) return o next End method
Any way of doing this? I am trying to implement a component based entity approach, and need method that will Return a component of an entity if it exists in the list.
TIA, and i hope this makes sense.