我的编译器是否与它认为重载函数混淆了?

zeb*_*und 1 c++ overloading compiler-errors function

我有以下标头功能:

float computeDistance3(Vector3f& vec_a, Vector3f& vec_b);

float computeDotProduct3(Vector3f& vecta, Vector3f& vectb);

float computeGeoDotProd3(Vector3f& vecta, Vector3f& vectb);
Run Code Online (Sandbox Code Playgroud)

具有以下定义

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;   
    }

}
Run Code Online (Sandbox Code Playgroud)

我知道他们的签名是一样的.这会让编译器感到困惑吗?我猜是这样的,因为当我编译代码时,我得到了这个:

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)   
Run Code Online (Sandbox Code Playgroud)

解除编译器混淆的解决方案是什么?

Mys*_*ial 5

&在定义中遗漏了一个:

float computeDotProduct3(Vector3f& vec_a, Vector3f vec_b) {
Run Code Online (Sandbox Code Playgroud)

应该:

float computeDotProduct3(Vector3f& vec_a, Vector3f& vec_b) {
Run Code Online (Sandbox Code Playgroud)

所以你最终会得到两个不同的(重载的)函数原型,这些原型只能通过引用来区分&- 因此是模糊的.