'No matching function call' 对于 subclass/superclass

'No matching function call' for subclass/superclass

我遇到了一个 'no matching function call' 错误,我不知道如何摆脱它,这似乎与我的子类没有被识别为超类有关。我有一个带有子类 Cube 的超类 Geometry,声明为:

class Cube : public Geometry {
    //code
    Intersection intersect(const Ray& ray_in, bool& intersected) const;
};

并且 Cube 有一个方法可以 return 一个交叉点:

Intersection Cube::intersect(const Ray& ray_in, bool& intersected) const {
    // code
    return Intersection(point, normal, t_near, this);   //point and normal are vec4, t_near is double
}

我有一个交集构造函数:

Intersection(const glm::vec4& _point, const glm::vec4& _normal, Geometry* _geometry, const double _t);

但是当我尝试编译时,我的 Cube::intersect 方法中的 return 行给出了错误:

no matching function for call to 'Intersection::Intersection(glm::vec4&, glm::vec4&, float&, const Cube*)'
   return Intersection(point, normal, t_near, this);
                                                  ^

为什么它不能识别 Cube 是 Geometry 的子类并尝试调用正确的 Intersection 构造函数?

这似乎与 subclasses 没有任何关系。构造函数的参数简直是错误的:

return Intersection(point, normal, t_near, this); 

不清楚 t_near 是什么,但很可能是 double。您将 double 作为第三个参数传递给构造函数,并将 this 作为第四个参数传递给构造函数,这显然必须是某种指针。在继续之前记下这一点...

然后,你还声称你的构造函数声明如下:

Intersection(const glm::vec4& _point, const glm::vec4& _normal,
             Geometry* _geometry, const double _t)

这就是您的问题中显示的内容。现在,问问自己:这个构造函数的第三个参数是 double,第四个参数是某种指针吗,因为你正在构造这个 class 的实例,在你的 return声明?