#include<iostream> using namespace std; class point { public: point(double a, double b,double c,double d); friend void dist(point*p); void show(); private: double u; double w; double x; double y; double z; }; point::point(double a, double b, double c, double d ) { u = a; w = b; x = c; y = d; } void dist(point*p) { p->z=sqrt((p->u -p->x)*(p->u -p-> x)+(p->w -p->y)*(p->w -p->y)); } void point::show() { cout << "the distance of the two point is:" << z << endl; } int main() { point chih(8,6,4,2); point *p; p = &chih; chih. show();
}
你忘了调用dist(p);
int main() { point chih(8, 6, 4, 2); point *p; p = &chih; dist(p); chih.show(); }