#include <iostream>
#include <cmath>
usingnamespace std;
struct Point
{
double x;
double y;
};
struct Route
{
Point data;
Route* next;
};
double distance(Point &a, Point &b);
double length(Route *s);
int main()
{
Point p1={2.4,1.2};
Point p2={-2,3.5};
Point p3={1.0,-1.0};
Route *r1= new Route;
Route *r2= new Route;
Route *r3= new Route;
(*r1).data=p1;
(*r1).next=r2;
(*r2).data=p2;
(*r2).next=r3;
(*r3).data=p3;
(*r3).next=NULL;
Route *first=r1;
cout <<" The length of a hurricaine track is: " <<length(first)<<endl;
system("Pause");
return 0;
}
double distance(Point& a, Point& b)
{
return sqrt((a.x-b.x)*(a.x-b.x) +(a.y-b.y)*(a.y-b.y));
}
double length(Route *s)
{
double gesDistance=0;
while(s->next!=0)
{
Route* following=s->next;
gesDistance = gesDistance + distance(s->data,following->data);
s=s->next;
}
return gesDistance;
}
The line which makes problems is: gesDistance = gesDistance + distance(s->data,following->data);
unfortunately I don't get the error of the compiler since the error is shown in a completly different file, which I didn't create. It says something about Point Iterators?!
That sounds like a name conflict. There is a std::distance that may be coming into scope by using namesapce std;. Try renaming your distance function, wrapping it in a namespace and/or using the scope resolution operator.
Thanks a lot for your help :-)
Now I get another error:
[Linker error] undefined reference to `Info::length(Route*)'
[Linker error] undefined reference to `Info::distance(Point&, Point&)'
I updated my code like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
namespace Info
{
double distance(Point &a, Point &b);
double length(Route *s);
}
// and
cout <<" The length of a hurricaine track is: " << Info::length(first)<<endl;
// and
gesDistance = gesDistance + Info::distance(s->data,following->data);