博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++官方文档-class
阅读量:6791 次
发布时间:2019-06-26

本文共 1793 字,大约阅读时间需要 5 分钟。

#include 
using namespace std;class Circle{ double radius;public: Circle(double r) { radius = r; } double area() { return 2 * radius; }};class Cylinder{ Circle base; double height;public: Cylinder(double r, double h) : base(r), height(h) { } double volume() { return base.area() * height; }};//uniform initializer//Cylinder::Cylinder(double r, double h)// : base { r }, height { h }//{//}class Rectangle{ int width, height;public: Rectangle(); Rectangle(int, int); void set_values(int, int); int area(void) { return width * height; } ;};Rectangle::Rectangle(){ width = 5; height = 5;}Rectangle::Rectangle(int x, int y) : width(x), height(y){}//Rectangle::Rectangle(int a, int b)//{// width = a;// height = b;//}void Rectangle::set_values(int x, int y){ width = x; height = y;}int main(){ Rectangle rect(3, 4); int myarea = rect.area(); cout << myarea << endl;// Circle foo(10.0); // functional form Circle bar = 20.0; // assignment init. Circle baz { 30.0 }; // uniform init. Circle qux = { 40.0 }; // POD-like// cout << foo.area() << endl; cout << bar.area() << endl; cout << baz.area() << endl; cout << qux.area() << endl; Rectangle rectb; // default constructor called Rectangle rectc(); // function declaration (default constructor NOT called) Rectangle rectd { }; // default constructor called Cylinder foo(10, 20); cout << "foo's volume: " << foo.volume() << '\n'; Rectangle* foop; foop = ▭ cout << foop->area() << endl; delete foop; return 0;}

 

posted on
2018-01-27 17:44 阅读(
...) 评论(
...)

转载于:https://www.cnblogs.com/shuiyonglewodezzzzz/p/8366673.html

你可能感兴趣的文章
heka
查看>>
Dart语言【003】变量与类型
查看>>
《设计模式 系列》- 创建型模式 - 构造者模式
查看>>
Android内核开发:图解Android系统的启动过程
查看>>
java基础知识汇总,不断更新中
查看>>
Java语言中单例模式的四种写法
查看>>
Uliweb 0.4发布
查看>>
什么时候选择压缩NTFS卷
查看>>
NTFS文件系统主要特点是什么?
查看>>
UIApplication的代理
查看>>
腾讯测试工程师:你以为会打LOL就能做测试了?
查看>>
Android对View进行包裹, 实现镜面反射效果
查看>>
docker-maven-plugin插件设置Docker的buildArgs
查看>>
没事儿瞎折腾!!
查看>>
如何训练自己面向对象思维模式
查看>>
mongodb2.6版本之用户管理
查看>>
使用Spring-loaded的热加载代码,免去更多的重启
查看>>
文件操作类
查看>>
iOS使用shell脚本批量修改属性
查看>>
Java多线程学习:wait与notify方法的使用
查看>>