初始化列表
1 // 2 // Box.hpp 3 // cplus 4 // 5 // Created by wanwan on 17/2/7. 6 // Copyright © 2017年 yuge. All rights reserved. 7 // 8 9 #ifndef Box_hpp10 #define Box_hpp11 12 #include13 14 class Box15 {16 public:17 double x;18 double y;19 double z;20 21 Box(double x,double y,double z);22 };23 24 #endif /* Box_hpp */
1 // 2 // Box.cpp 3 // cplus 4 // 5 // Created by wanwan on 17/2/7. 6 // Copyright © 2017年 yuge. All rights reserved. 7 // 8 9 #include "Box.hpp"10 #include11 using namespace std;12 13 Box::Box(double x,double y,double z):x(x),y(y),z(z)14 {15 cout<< "x,y,z = "< <<","< <<","< <
1 // 2 // main.cpp 3 // cplus 4 // 5 // Created by wanwan on 17/2/7. 6 // Copyright © 2017年 yuge. All rights reserved. 7 // 8 9 #include10 #include "Box.hpp"11 using namespace std;12 13 int main(int argc, const char * argv[]) {14 15 Box box1(10,20,30);16 return 0;17 }18 19 /*20 结果:21 x,y,z = 10,20,3022 */