Reputation: 10137
I have the following header functions:
float computeDistance3(Vector3f& vec_a, Vector3f& vec_b);
float computeDotProduct3(Vector3f& vecta, Vector3f& vectb);
float computeGeoDotProd3(Vector3f& vecta, Vector3f& vectb);
With the following definitions
float computeDistance3(Vector3f& vec_a, Vector3f& vec_b) {
float x = vec_a.x - vec_b.x;
float y = vec_a.y - vec_b.y;
float z = vec_a.z - vec_b.z;
return sqrt((x * x) + (y * y) + (z * z));
}
float computeDotProduct3(Vector3f& vec_a, Vector3f vec_b) {
return (vec_a.x * vec_b.x)
+ (vec_a.y * vec_b.y)
+ (vec_a.z * vec_b.z);
}
float computeGeoDotProd3(Vector3f& vecta, Vector3f& vectb) {
float amag, bmag, dotProd;
amag = vecta.computeMagnitude();
bmag = vectb.computeMagnitude();
dotProd = computeDotProduct3(vecta, vectb);
bool notZero = (amag != 0.0f && bmag != 0.0f) && dotProd != 0.0f;
if (notZero) {
return cosf(dotProd / (amag * bmag));
} else {
return -1.0f;
}
}
I know that their signatures are the same. Is this confusing the compiler? I'm guessing so, because when I compile the code, I get this:
vector3f.cpp: In function ‘float computeGeoDotProd(Vector3f&, Vector3f&)’:
vector3f.cpp:139:43: error: call of overloaded ‘computeDotProduct3(Vector3f&, Vector3f&)’ is ambiguous
vector3f.cpp:139:43: note: candidates are:
vector3f.h:31:7: note: float computeDotProduct3(Vector3f&, Vector3f&)
vector3f.cpp:127:7: note: float computeDotProduct3(Vector3f&, Vector3f)
Question
What is the solution to unconfusing the compiler?
Upvotes: 1
Views: 135
Reputation: 471209
You're missing an &
in the definition:
float computeDotProduct3(Vector3f& vec_a, Vector3f vec_b) {
should be:
float computeDotProduct3(Vector3f& vec_a, Vector3f& vec_b) {
So you end up with two different (overloaded) function prototypes that differ only by the reference &
- hence ambiguous.
Upvotes: 5