- 1 博客内容
- 2 代码_类
之前看C++特性,不知所然,今天得空回顾以下,似有所或。
参考B站视频和RUNOOB,码字记录。
2 代码_类#includeusing namespace std; class Box { public: double length; // 长度 double breadth; // 宽度 double height; // 高度 double get(void); void set(double l, double b, double h); }; double Box::get(void) { return length * breadth * height; } void Box::set(double len, double bre, double hei) { length = len; breadth = bre; height = hei; } int main() { Box a; double volume = 0.0; // 用于存储体积 a.set(16.0, 8.0, 12.0); volume = a.get(); cout << "a 的体积:" << volume << endl; return 0; }
PS:使用 VS Code, C++11。



