我在光线跟踪任务的工作冲突,这里是有问题的来源:从两个类继承,具有相同功能的原型类,互相
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
}
};
源之上无法编译,错误信息:
error: conflicting return type specified for ‘virtual bool BoundingSphere::intersectionTest(const Ray&)’
error: overriding ‘virtual RayTask Sphere::intersectionTest(const Ray&)
我想在球的使用方法来实现BoundingSphere所:: intersectionTest,所以我需要从两个包围体和球体继承。但由于继承函数具有不同的返回类型相同的参数列表,事情搞砸了......
我不想重复具有相同功能的代码... 可以任何一个给我一个解决方案? ..
只有使用不同的返回类型才能做到这一点。方法签名是方法名称,其参数的数量和类型,在这里都是相同的。 – DumbCoder 2012-04-29 14:44:34
谢谢...我必须更改我的函数名称... – Tim 2012-04-29 14:56:41
修饰符(如const)也构成方法签名的一部分 – EdChum 2012-04-29 15:08:44