博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
监控服务脚本
查看>>
Java多线程设计模式(7)线程独有储藏库模式
查看>>
电商一定是一元化结构
查看>>
Android双缓冲技术
查看>>
我的友情链接
查看>>
BZOJ1005:[HNOI2008]明明的烦恼(组合数学,Prufer)
查看>>
AtCoder Regular Contest
查看>>
java 通过httpclient调用https 的webapi
查看>>
以todomvc为例分析knockout、backbone和angularjs
查看>>
关于img标签浏览器自带的边框,清除边框的解决方式(即img[src=""] img无路径情况下,灰色边框去除解决方法)...
查看>>
在react native中使用mobx时初始化页面数据
查看>>
wpf呈现UIElment的缩略图
查看>>
初识python
查看>>
问题:鼠标放在卡片最下端发生不停闪动
查看>>
Unity打包/读取AssetBundle资源全教程
查看>>
1208. [HNOI2004]宠物收养场【平衡树-splay】
查看>>
python环境Anaconda的安装
查看>>
(十九)加载指令
查看>>
mysqlbackup
查看>>
MySQL视图小例子
查看>>