【发布时间】:2017-09-06 05:07:54
【问题描述】:
我收到一个“没有匹配的函数调用”错误,我无法弄清楚如何摆脱它,这似乎与我的子类未被识别为超类有关。我有一个带有子类 Cube 的超类 Geometry,声明为:
class Cube : public Geometry {
//code
Intersection intersect(const Ray& ray_in, bool& intersected) const;
};
而 Cube 有一个返回 Intersection 的方法:
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 构造函数:
Intersection(const glm::vec4& _point, const glm::vec4& _normal, Geometry* _geometry, const double _t);
但是当我尝试编译时,我的 Cube::intersect 方法中的返回行给出了错误:
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 构造函数?
【问题讨论】:
标签: c++ subclass superclass