I have a source code file in C++. Here it is:
#include <iostream>
using namespace std;
class myPoint
{
public:
double x;
double y;
myPoint() {x=y=0;}
};
double distance(myPoint A, myPoint B)
{
return (A.x - B.x);
}
int main()
{
myPoint A, B;
A.x=5; A.y=5;
B.x=3; B.y=2;
cout << distance(A, B) << endl;
return 0;
}
And my compiler (Microsoft Visual Studio C++ 2012) gives me the following error:
...
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2039: 'iterator_category' : is not a member of 'myPoint'
1> d:...\source.cpp(5) : see declaration of 'myPoint'
...
When I removed using namespace std;
and changed cout << distance(A, B) << endl;
to
std::cout << distance(A, B) << std::endl;
my program worked.
Why does the first version give me an error? What is the mistake?