C++编程Point(类与对象)?

C++编程Point(类与对象)


LEATH
浏览 1151回答 4
4回答

慕妹3146593

Line L1(Point M,Point N);这种形式,VS2008中,编译器会给出警告C4930:未调用原型函数。编译器理解为这是在main内部声明了一个函数。这也是为什么VS2005和VS6.0不执行的原因。因为是函数原型声明,当然不会执行。正确调用方法是,参数不要再写类型了Line L1(m, n); // 这样编译器就知道,你是声明了Line的实例变量

斯蒂芬大帝

Line L1(Point(),Point());就可以了,函数的参数列表里是不能声明变量的,可以直接传递匿名对象(注意对象后的括号,就算没参数也要加括号)如果要传递带参数的Point可以这样Line L1(Point(1,2), Point(3,4));

慕哥9229398

Append Code:class Point{int x, y;public:Point(int px=0,int py=0){x=px; y=py;cout <<"Point : (" <<x <<"," <<y <<") is erased.\n";}Point(const Point& pt){x=pt.x; y=pt.y;cout <<"Point : (" <<x <<"," <<y <<") is copied.\n";}~Point(){cout <<"Point : (" <<x <<"," <<y <<") is erased.\n";}void show(){cout <<"Point : (" <<x <<"," <<y <<")\n";}};
打开App,查看更多内容
随时随地看视频慕课网APP