との競合が問題の原因である:上記2クラスから継承したクラス、同じ関数プロトタイプで、私はここでは、レイトレーシングのタスクに取り組んでいますお互い
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を実装したいので、私はBoundingVolumeと球の両方から継承する必要があります。同じ戻り値の型を持つ同じパラメータリストを持つ関数を継承するため、ものが混乱してしまいます。
私は同じ機能を持つコードを複製したくありません... 私に解決策を与えることができますか? ..
異なる返品タイプを使用することによってのみ行うことはできません。メソッドのシグネチャはメソッド名とそのパラメータの数と型です。ここでは両方とも同じです。 – DumbCoder
ありがとう...関数名を変更する必要があります... – Tim
constなどの修飾子もメソッドシグネチャの一部を構成します – EdChum