Original Post
I have an interface class called CollidableObject, something like this:
class CollidableObject{
public:
virtual INTERSECTION isCollide(const CollidableObject &) = 0;
}
Now I currently have two derived classes called BoundingSphere and Ray2d. In the Ray2d isCollide function I assume (for now) that I am passed a BoundingSphere object and try to do this in the function:
INTERSECTION Ray2d::isCollide(const CollidableObject& co)
{
...
BoundingSphere *b = co;
float radius = b->getRadius();
...
}
But the compiler tells me that it "cannot convert from 'const CollidableObject' to 'BoundingCircle *'" I tried using casting i.e. BoundingSphere *b = (BoundingSphere) co; but it says no constructor could take the source type. Is there anyway to have a pointer of type derived class point to it's base class? I need to use the getRadius() among other things from the derived BoundingSphere class. Thanks!