点和线类在c?
发布时间:2020-12-16 05:33:47 所属栏目:百科 来源:网络整理
导读:我正在学习C(和一般的编程),我正在努力做一个Point类和一个Line类. 线应由2点对象组成. C大师可以看看我的工作,告诉我这是怎么适当地使用指针,引用和类? class Point{ private: int x,y; public: Point() : x(0),y(0) {} Point(int x,int y) : x(x),y(y) {}
我正在学习C(和一般的编程),我正在努力做一个Point类和一个Line类.
线应由2点对象组成. C大师可以看看我的工作,告诉我这是怎么适当地使用指针,引用和类? class Point { private: int x,y; public: Point() : x(0),y(0) {} Point(int x,int y) : x(x),y(y) {} } class Line { private: Point *p1; Point *p2; public: Line(Point &p1,Point &p2) : p1(p1),p2(p2) {} void setPoints(Point &p1,Point &p2) { this->p1 = p1; this->p2 = p2; } } 解决方法
你不应该在你的代码中使用指针.使用实际物体.指针实际上在C中很少使用.
class Point { private: int x,y(y) {} } class Line { private: Point p1; Point p2; public: Line(const Point & p1,const Point & p2 ) : p1(p1),p2(p2) {} void setPoints( const Point & ap1,const Point & ap2) { p1 = ap1; p2 = ap2; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |