I'm getting a 'no matching function call' error that I can't figure out how to get rid of, and it seems to have to do with my subclass not being recognized as the superclass. I have a superclass Geometry with a subclass Cube, declared as:
class Cube : public Geometry {
//code
Intersection intersect(const Ray& ray_in, bool& intersected) const;
};
and Cube has a method to return an 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
}
I have an Intersection constructor:
Intersection(const glm::vec4& _point, const glm::vec4& _normal, Geometry* _geometry, const double _t);
but when I try to compile, the return line in my Cube::intersect method gives the error:
no matching function for call to 'Intersection::Intersection(glm::vec4&, glm::vec4&, float&, const Cube*)'
return Intersection(point, normal, t_near, this);
^
Why would it not recognize that Cube is a subclass of Geometry and attempt to call the correct Intersection constructor?
This doesn't appear to have anything to do with subclasses. The constructor's parameters are simply wrong:
return Intersection(point, normal, t_near, this);
It's not clear what t_near
is, but it's likely to be a double
. You're passing a double
for the third parameter to the constructor, and this
as the fourth parameter to the constructor, which obviously must be some kind of pointer. Make a mental note of that, before going further...
Then, you also claim that your constructor is declared as follows:
Intersection(const glm::vec4& _point, const glm::vec4& _normal,
Geometry* _geometry, const double _t)
That's what's shown in your your question. Now, ask yourself this: is the third parameter to this constructor a double
, and the fourth parameter a some kind of a pointer, as you're constructing an instance of this class, in your return
statement?