正在加载图片...
内嵌对象初始化:初始化列表 class Point //声明Point类 ex10_class_Line_01.cpp public: Point(double newx,double newy) /1构造函数 private: double x,y; } class Line /声明Line类 public: Line(double xA,double yA,double xB,double yB) :p1(xA,yA),p2(xB,yB){}/I组合类构造函数 private: Point p1,p2; 总的参数列表中的参数需要带数据类型(形参),初始化列表则不需要。 http://math.ecnu.edu.cn/~jypan http://math.ecnu.edu.cn/~jypan 7 内嵌对象初始化:初始化列表 class Point // 声明Point类 { public: Point(double newx, double newy) // 构造函数 ... ... private: double x, y; }; class Line // 声明Line类 { public: Line(double xA, double yA, double xB, double yB) :p1(xA, yA),p2(xB,yB) { } // 组合类构造函数 ... ... private: Point p1, p2; }; ex10_class_Line_01.cpp † 总的参数列表中的参数需要带数据类型(形参),初始化列表则不需要
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有