I am working on a Ray Tracing task, here is the problematic source:
class Geometry
{
public:
virtual RayTask *intersectionTest(const Ray &ray) = 0;
};
class Sphere : public Geometry
{
public:
RayTask *intersectionTest(const Ray &ray);
};
class BoundingVolume
{
public:
virtual bool intersectionTest(const Ray &ray) = 0;
};
class BoundingSphere : public Sphere, BoundingVolume
{
public:
bool intersectionTest(const Ray &ray) // I want this to be inherited from BoundingVolume
{
return Sphere::intersectionTest(ray) != NULL; // use method in Sphere
}
};
source above can not compile, error information:
error: conflicting return type specified for ‘virtual bool BoundingSphere::intersectionTest(const Ray&)’
error: overriding ‘virtual RayTask Sphere::intersectionTest(const Ray&)
I want to implement BoundingSphere::intersectionTest using method in Sphere, so I need to inherit from both BoundingVolume and Sphere. but due to inherit functions that has the same parameter list with different return type, things messed up...
I do not want to duplicate codes with the same functionality... could any one give me a solution?...