Error reference to ‘distance’ is ambiguous [duplicate]

  ambiguous-call, c++, c++17, friend-function, reference

I cannot figure out why I am getting the error "reference to 'distance' is ambiguous".
I have passed class object as an argument in friend function.

#include <iostream>
using namespace std;

class distance {
    int meters = 0;
public:
    distance() {}
    void displaydata() {
        cout << "Meters Value:" << meters;
    }
    //Prototype
    friend void addvalue(distance &d);
};

void addvalue(distance &d) {
    d.meters += 5;
}

int main() {
    distance d1; // meters = 0
    d1.displaydata(); // 0
    // The friend function call
    addvalue(d1); // pass by reference
    d1.displaydata();
}

Source: Windows Questions C++

LEAVE A COMMENT