I am trying to overload the * operator in order to multiply two objects (dot product).
These objects can be Point3D, Vector3D or Normal. They all basically have the same structure (an x, y, and z value), I’ve only split them up for semantics.
The line that is giving me trouble is this:
float t = (point - r.origin)*normal / (r.direction * normal);
Here, point and r.origin are a Point3D, normal is a Normal and r.direction is a Vector3D. In the header files for these classes I have the following overload functions:
In Vector3D.h:
Vector3D operator *(Normal& n);
In Point3D.h:
Point3D operator -(Point3D& p);
Point3D operator *(Normal& n);
The error I get is:
No match for 'operator*' in 'r->Ray::direction * ((const Plane*)this)->Plane::normal'
Assuming I have correctly filled out the functions in the .cpp file, is there anything stupid I’ve done here? Also, ignore the fact that there is no division operator yet…It’s in the pipeline!
Cheers
You may have defined the unary versions instead of the binary versions. (Did you define them inside the class { … } ? )
Or you may have not defined them as const. Try this:
For binary functions over hetrogeneous parameters like this I find it a lot easier to define them all together at global scope in a seperate file/place and friend them from the classes.