#includeusing namespace std; class Line{ public: int getLength(); Line(int len); Line(const Line &obj); ~Line(); private: int *ptr; }; Line::Line(int len){ cout << "Line 构造函数调用" << endl; ptr = new int; *ptr = len; } Line::Line(const Line &obj){ cout << "Line的拷贝构造函数调用" << endl; ptr = new int; *ptr = *obj.ptr; //ptr = obj.ptr; } Line::~Line(){ cout << "Line的析构函数调用" << endl; delete ptr; } int Line::getLength(){ return *ptr; } void display(Line obj){ cout << "Line大小:" << obj.getLength() << endl ; } int main() { Line line(10); display(line); return 0; }



