#include <iostream> using std::cout; using std::endl; class Point { public: Point(int x0 = 0, int y0 = 0); Point(const Point&p ); ~Point() = default; int get_x() const { return x; } int get_y() const { return y; } void show() const; private: int x, y; }; Point::Point(int x0, int y0): x{x0}, y{y0} { cout << "constructor called." << endl; } Point::Point(const Point& p): x{p.x}, y{p.y} { cout << "copy constructor called." << endl; } void Point::show() const { cout << "(" << x << ", " << y << ")" << endl; } int main() { Point p1(5, 6); p1.show(); Point p2 = p1; p2.show(); Point p3(p2); p3.show(); cout << p3.get_x() << endl; }
标签:std,const,Point,int,实验,y0,x0 From: https://www.cnblogs.com/wyh-205113/p/16741865.html