Trouble Testing Classes

Hi- Working on an assignment that involves using to classes - one for the Points on a line and the other for the LineSegment. The code seems to work but when I try to run a test against the test script I get this error message.



/tmp/ccnPvsEd.o: In function `Point::Point(double, double)':
Point.cpp:(.text+0x0): multiple definition of `Point::Point(double, double)'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x0): first defined here
/tmp/ccnPvsEd.o: In function `Point::setXCoord(double)':
Point.cpp:(.text+0x10c): multiple definition of `Point::setXCoord(double)'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x10c): first defined here
/tmp/ccnPvsEd.o: In function `Point::setYCoord(double)':
Point.cpp:(.text+0x126): multiple definition of `Point::setYCoord(double)'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x126): first defined here
/tmp/ccnPvsEd.o: In function `Point::Point(double, double)':
Point.cpp:(.text+0x0): multiple definition of `Point::Point(double, double)'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x0): first defined here
/tmp/ccnPvsEd.o: In function `Point::Point()':
Point.cpp:(.text+0x3a): multiple definition of `Point::Point()'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x3a): first defined here
/tmp/ccnPvsEd.o: In function `Point::Point()':
Point.cpp:(.text+0x3a): multiple definition of `Point::Point()'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x3a): first defined here
/tmp/ccnPvsEd.o: In function `Point::distanceTo(Point)':
Point.cpp:(.text+0x68): multiple definition of `Point::distanceTo(Point)'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x68): first defined here
/tmp/ccnPvsEd.o: In function `Point::getXCoord()':
Point.cpp:(.text+0x142): multiple definition of `Point::getXCoord()'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x142): first defined here
/tmp/ccnPvsEd.o: In function `Point::getYCoord()':
Point.cpp:(.text+0x15c): multiple definition of `Point::getYCoord()'
/tmp/ccyuvj0A.o:LineSegment.cpp:(.text+0x15c): first defined here

Also, not sure what the best way to insert code into these forums is so please excuse me if this is not the best way.

But, here is the code I have for the Point class. Any help is much appreciated.


class Point

{ private:

double XCoord;
double YCoord;

public:

Point(double,double);
Point();
double distanceTo(Point);
void setXCoord(double);
void setYCoord(double);
double getXCoord();
double getYCoord();

};


#include <iostream>
#include <cmath>
#include "Point.hpp"
using namespace std;


Point::Point(double x,double y)
{ setXCoord (x); setYCoord (y);
}

Point::Point()
{ setXCoord (0); setYCoord (0);
}

double Point::distanceTo(Point p2)
{ double dist = pow((XCoord - p2.getXCoord()),2) + pow((YCoord-p2.getYCoord()),2);
return sqrt(dist);
}

void Point::setXCoord(double x)
{ XCoord = x;
}

void Point::setYCoord(double y)
{ YCoord = y;
}

double Point::getXCoord()
{ return XCoord;
}

double Point::getYCoord()
{ return YCoord;
}
/*
int main()
{
Point p1(-1.5,0.0);
Point p2(1.5,4.0);
cout<<p1.distanceTo(p2)<< endl;
return 0;
}
*/
I guess that the class Point is in it's own header. Use include guards to avoid multiple definitions:

http://en.wikipedia.org/wiki/Include_guard


Please use code tags: [code]Your code[/code]
Read this: http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.