I have a List<CollisionBase> in which I will be going through and calling a method known as Intersect. CollisionBase and all of the derived classes have this method defined, with the CollisionBase class having it as virtual and the defined classes having it as override.
This list will contain up to three different derived classes in it (CollisionCircle, CollisionRectangle, CollisionLine), but I will not known until runtime what the list will contain. Is there anyway to "typecast" the function call Intersect to it calls the right function in the class that is currently being looked at in the list? I have the function I am using for this below:
Expand|Select|Wrap|Line Numbers
- foreach (CollisionBase c in collisionListVar)
- {
- if (c.Intersect(input))
- {
- return true;
- }
- }