编码 :
std::ostream& operator << (std::ostream& out, point p) {
out << "(" << p.x << ", "<< p.y<< ", "<< p.z << ")";
return out;
}
错误:
'std::ostream& KillThemAll::point::operator<<(std::ostream&, KillThemAll::point)' 必须只取一个参数 std::ostream& operator<< (std::ostream& out, point p) { out << "(" << px << ", "<< py<< ", "<< pz << ")"; 返回;}
实际上,代码在“科学计算中的问题和解决方案”的第 402 页类似(除了我使用 3D 而不是 2D)。
为了您的好奇心,这里是强大的结构«点»:
struct point{
double x,y,z;
point() { x=y=z=0.0;}
point(double _x, double _y, double _z){this->x=_x, this->y=_y, this->z=_z;}
point operator - (const point& _p) const { return point(x-_p.x, y-_p.y, z-_p.z);}
point operator + (const point& _p) const { return point(x+_p.x, y+_p.y, z+_p.z);}
double operator * (const point& _p) const { return x*_p.x+y*_p.y+z*_p.z;}
point operator * (const double _t) const { return point(_t*x, _t*y, _t*z);}
point operator / (const double _t) const { if(_t!=0) return point(x/_t, y/_t, z/_t);}
};