0

For the line Point::setPoint(... it tells me that it is invalid and I set it to Point::&setPoint(.. with then stats it is a illegal operation. I'm a little lost on this one anyone mine pointing me in the right direction.

class Point
{
public:
	Point(double=0.0, double=0.0);
	Point &setPoint(double xPoint, double yPoint);
	double distance(Point & p);
	void print() const;
private:
	double x;
	double y;
	};

Point::setPoint(double xPoint, double yPoint)
{  
	xPoint = x; 
	yPoint = y; 
	return *this; 
}

double Point::distance(Point &p)
{
	double dis; 
	dis = sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
	return dis; 
}

void Point::print() const
{
	cout << "(" << x << ", " << y << ")" << endl; 
}

int main() 
{
	Point myObject, myObject2; 
	myObject.setPoint(4,5).print();
	myObject2.setPoint(3,4).print();
	return 0; 
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by VernonDozier
0

Everything but a constructor needs a return type, so I assume you want this:

Point& Point::setPoint(double xPoint, double yPoint)

since it matches this declaration in the Point class (see red):

class Point
{
public:
	Point(double=0.0, double=0.0);
	Point &setPoint(double xPoint, double yPoint);
	double distance(Point & p);
	void print() const;
private:
	double x;
	double y;
	};
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.