p2.setXCoord(double); // <-- error
p2.setYCoord(double); // <-- error
double is a type, not a valid actual parameter name.
Call those functions with a value or a variable that is double or at least convertible to double.
double is a reserved keyword for the double type, it can't be passed to a function as an argument, you need to forward the actual values from the Point type.
void LineSegment::setEnd1(Point p1) {
p1.setXCoord(p1.getXCoord());
p1.setYCoord(p1.getYCoord());
}
double is a type specifier not an object. And why does for example setEnd1 call itself?
It seems you mean the following
//set and get points
void LineSegment::setEnd1(Point p1) {
this->p1.setXCoord(p1.getXCoord()); // <-- error
this->p1.setYCoord(pq.getYCoord()); // <-- error
}
void LineSegment::setEnd2(Point p2) {
this->p2.setXCoord(p2.getXCoord()); // <-- error
this->p2.setYCoord(p2.getXCoord()); // <-- error
}
You could write even simpler
//set and get points
void LineSegment::setEnd1(Point p1) {
this->p1 = p1;
}
void LineSegment::setEnd2(Point p2) {
this->p2 = p2;
}
And at least in the class Point all these member functions should be declared with qualifier const
double getXCoord() const;
double getYCoord() const;
double distanceTo(const Point&) const;
void LineSegment::setEnd1(Point p1) {
p1.setXCoord(double); // <-- error
p1.setYCoord(double); // <-- error
setEnd1(p1);
}
LineSegment的set函数每个都接受Point类的一个参数。所以当你给它一个Point类型的变量时,你必须将它保存为point。
void Point::setXCoord(double x) {
xCoord = x;
}
您的代码的这一部分是您想要做的事情的模板。您需要为p1键入Point,而不是调用目标。
。而不是类型double