So I have this program that has a 3D point class and a function that finds out the distance between two points. When I use the distance function normally in the main, it gives an error. But when I add scope resolution operator, the code works. What is causing the error and how the scope resolution operator is fixing it?
This error occurs in Dev-C++ and Codeblocks but works fine with Atom IDE using gpp-compiler plugin with MinGW compiler.
#include <iostream>
#include <cmath>
using namespace std;
class Point{...} //Class object with x, y, and z variable and has functions to return values
float distance(Point p1, Point p2);
int main() {
Point P1, P2;
d = distance(P1, P2); // throws an error but just adding -> ::distance(P1, P2) works fine! why?
cout << "Distance between P1 and P2: " << d << endl;
return 0;
}
float distance(Point p1, Point p2) {
float d;
int x0 = p1.getX(), y0 = p1.getY(), z0 = p1.getZ();
int x1 = p2.getX(), y1 = p2.getY(), z1 = p2.getZ();
d = sqrt(pow((x1-x0),2) + pow((y1-y0), 2) + pow((z1-z0), 2));
return d;
}