Can't find the error.

Can anyone please tell what is wrong in the following code. The Compiler points to the 33rd line and opens up another file. I am trying to compute the distance between two points. The error message is as follows::

E:\C++\Classpractice.cpp|33|instantiated from here|
c:\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_iterator_base_types.h|127|error: no type named 'iterator_category' in 'class point'|
c:\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_iterator_base_types.h|128|error: no type named 'value_type' in 'class point'|
c:\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_iterator_base_types.h|129|error: no type named 'difference_type' in 'class point'|
c:\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_iterator_base_types.h|130|error: no type named 'pointer' in 'class point'|
c:\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\bits\stl_iterator_base_types.h|131|error: no type named 'reference' in 'class point'|
||=== Build finished: 5 errors, 0 warnings ===|

....................................................................
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
#include<math.h>
using namespace std;
class point
{
  public:
  point(int x_i,int y_i){x=x_i;y=y_i;};
  ~point(){};
  void setc(int x_l,int y_l){x=x_l,y=y_l;};
  int getc_x()const{return x;};
  int getc_y()const{return y;};
  private:
  int x;
  int y;
};
float distance(point,point);
int main()
{
    int x,y;
    float d;
    point a(0,0),b(0,0);
    cout<<"Insert x coordinate of point 1:\n";
    cin>>x;
    cin.ignore();
    cout<<"\nInsert y coordinate of point 1:\n";
    cin>>y;
    a.setc(x,y);
    cout<<"\nInsert x coordinate of point 2:\n";
    cin>>x;
    cout<<"\nInsert y coordinate of point 2:\n";
    cin>>y;
    b.setc(x,y);
    d=distance(a,b);
    
    cout<<"\nThe Distance between them is "<<d;



    return 0;
}
float distance(point a,point b)
{
    float d;
    int x1,x2,y1,y2,q,w,e,r;
    x1=a.getc_x();
    x2=b.getc_x();
    y1=a.getc_y();
    y2=b.getc_y();
    q=(x1-x2)*(x1-x2);
    w=(y1-y2)*(y1-y2);
    e=q+w;
    d=sqrt(e);




    return d;
}

.........................................................................
Last edited on
Perhaps a name conflict with std::distance (which might be included in iostream or something). Try renaming distance to something else or placing it in it's own namespace.

I also wonder if calling it with ::distance will work... Let me know how it turns out!

BTW, if you post the error message that makes it much easier to identify what's happening. I'm just guessing here.
Last edited on
Topic archived. No new replies allowed.