using namespace std; class Point { public: double x; double y; Point(){} void setPoint(double x,double y ) { this->x = x; this->y = y; } Point(double xx,double yy) { this->x=xx; this->y=yy; } }; class Point1 { public: Point point; void set() { point.x=1; point.y=2; cout<<point.x<<point.y<<endl; } }; class Point2 { public: Point point; void set(Point point) { point.x=1; point.y=2; cout<<point.x<<point.y<<endl; } }; class Point3 { public: Point point; void set(Point &point) { point.x=1; point.y=2; cout<<point.x<<point.y<<endl; } }; int main(int argc,char *argv[]) { Point1 point1; point1.set(); cout<<point1.point.x<<point1.point.y<<endl; Point2 point2; point2.set(point2.point); cout<<point2.point.x<<point2.point.y<<endl; Point3 point3; point3.set(point3.point); cout<<point3.point.x<<point3.point.y<<endl; return 0; }
c++中要想让内部操作印象到外部,需要使用引用或者指针。
java中将摒弃指针,全部使用引用进行操作。
时间: 2024-10-03 22:49:03