don't understand how to fix error

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

don't understand how to fix error

Post by StatujaLeha »

Judge doesn't compile next code and I don't understand why.

Code: Select all

#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <algorithm>

#define sqr(a) ((a)*(a))

struct Point 
{
    int x,y;

    Point(){}
    Point(int X,int Y):x(X),y(Y){}
};

double distance(Point const &l,Point const &r)
{
    return sqrt(double(sqr(l.x - r.x) + sqr(l.y - r.y)));
}

double polarAngle(Point const &origin,Point const &otherPoint)
{
    double angle = acos((otherPoint.x - origin.x)/distance(origin,otherPoint));

    return angle;
}
void main(){}
There are next errors:
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h: In instantiation of
`iterator_traits<Point>':
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:305: instantiated
from here
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:104: no type named
`iterator_category' in `struct Point'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:105: no type named
`value_type' in `struct Point'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:106: no type named
`difference_type' in `struct Point'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:107: no type named
`pointer' in `struct Point'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:108: no type named
`reference' in `struct Point'
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h: In function `double
polarAngle(const Point &, const Point &)':
/usr/local/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/../../../../include/g++-3/stl_iterator.h:305: no type named
`difference_type' in `struct iterator_traits<Point>'


If I cut function polarAngle(...) then judge compile code.

Code: Select all

#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <algorithm>

#define sqr(a) ((a)*(a))

struct Point 
{
    int x,y;

    Point(){}
    Point(int X,int Y):x(X),y(Y){}
};

double distance(Point const &l,Point const &r)
{
    return sqrt(double(sqr(l.x - r.x) + sqr(l.y - r.y)));
}

void main(){}
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

There's a function distance() in STL.
You'd better rename your distance() to something else, e.g. dist().
StatujaLeha
Learning poster
Posts: 91
Joined: Tue May 31, 2005 2:01 pm
Location: Russia

Post by StatujaLeha »

спасибо
Post Reply

Return to “C++”