每个 case 语句的结尾不要忘了加 break,否则将导致多个分支重叠
每个 case 语句的结尾不要忘了加 break,否则将导致多个分支重叠 (除非有意使多个分支重叠)。
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
//定义一个枚举类型
enum Color {Red,Yellow,Green,White};
//圆类Circle的定义
class Circle {
float radius;
public:
Circle(float r) {
radius=r;
cout<<"Circle initialized!"<<endl;
}
~Circle() { //析构函数
cout<<"Circle destroyed!"<<endl;
}
float Area() {
return 3.1416*radius*radius;
}
};
//桌子类Table的定义
class Table {
float height;
public:
Table(float h) {
height=h;
cout<<"Table initialized!"<<endl;
}
~Table() { //构造函数
cout<<"Table destroyed!"<<endl;
}
float Height() {
return height;
}
};
//圆桌类RoundTable的定义
class RoundTable:public Table,public Circle {
Color color;
public:
RoundTable(float h,float r,Color c); //构造函数
int GetColor() {
return color;
}
~RoundTable() { //构造函数
cout<<"RoundTable destroyed!"<<endl;
}
};
//圆桌构造函数的定义
RoundTable::RoundTable(float h,float r,Color c):Table(h),Circle(r)
{
color=c;
cout<<"RoundTable initialized!"<<endl;
}
//测试多继承中构造函数和析构函数的执行方式
int main(int argc, char** argv) {
RoundTable cir_table(15.0,2.0,Yellow);
cout<<"The table properties are:"<<endl;
//调用Height类的成员函数
cout<<"Height="<<cir_table.Height()<<endl;
//调用circle类的成员函数
cout<<"Area="<<cir_table.Area()<<endl;
//调用RoundTable类的成员函数
cout<<"Color="<<cir_table.GetColor()<<endl;
return ;
}
每个 case 语句的结尾不要忘了加 break,否则将导致多个分支重叠的更多相关文章
- swtich和case语句中,定义变量要加花括号
转自: http://blog.chinaunix.net/uid-27103408-id-3340702.html http://www.xuebuyuan.com/2070170.html swi ...
- java学习笔记08-switch case语句
switch是一种选择语句,可以通过匹配某个条件,来执行某块代码 switch(expression){ case value: break;//可选 default://可选 //语句 } swit ...
- shell实战之case语句的选择提示
知识点包括:case语句,cat多行输入,break和exit的区别,wget断点续传,while中断条件写法,函数的使用方法 #!/bin/bash echo "\n1. 本机容器情况如下 ...
- Oracle IF & CASE语句
IF语句主要有以下三种基本形式: 一. IF-THEN语句 IF CONDITION THEN STATEMENT 1; ... STATE ...
- linux基础16-bash编程(case语句及脚本选项 )
(1) case语句:选择结构 case SWITCH in value1) statement ... ;; //双分号结尾. value2) statement ... ;; *) stateme ...
- if语句和case语句用法展示
if语句和case语句用法展示 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.单分支if条件语句 1>.语法格式一 if [ 条件判断式 ];then 源代码 fi 2& ...
- Linux Shell编程case语句
http://blog.csdn.net/dreamtdp/article/details/8048720 case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变 ...
- SHELL用法五(Case语句)
1.SHELL编程Case语句案例实战 1)Case选择条件语句的格式: case $INPUT in Pattern1) 语句1 ;; Pattern2) 语句2 ;; esac 2)Case语句企 ...
- switch case语句,switch case用法详解
switch 是"开关"的意思,它也是一种"选择"语句,但它的用法非常简单.switch 是多分支选择语句.说得通俗点,多分支就是多个 if. 从功能上说,sw ...
随机推荐
- python 下载.whl 文件,查看已安装软件包方法
下载地址 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 另一个Python packages地址为 https://pypi.org/ 下载 ...
- win7 64 安装scikit-learn
1. scikit-learn简单介绍 scikit-learn是一个基于NumPy.SciPy.Matplotlib的开源机器学习工具包.採用Python语言编写.主要涵盖分类. 回归和聚类等算法, ...
- 把git上的larave项目通过SourceTree安装上再通过composer安装依赖库
1.项目地址克隆 https://gitee.com/fps2tao/laravel5.5-alitaobao.git 通过SourceTree工具下载到本地 2.在命令行方式打开项目地址安装依赖库( ...
- unity 显示帧率
Game视图右上角Stats按钮按下即可显示统计信息.
- Oracle学习笔记之三,Oracle 11g数据库的启动与关闭
SQL*PLus命令 SQLPLUS username[/password][@connect_identifier][AS SYSOPER|SYSDAB] 1. 启动数据库实例 STARTUP [n ...
- Statistical Concepts and Market Returns
Statistical Concepts and Market Returns Categories of statistics Descriptive statistics: used to sum ...
- [100]linux输入输出重定向
一目了然版本: &号含义: 参考 参考:非常经典,值得一看,我是在linux爱好者公众号里发现的. 下面是我自己的一些总结. linux的命令数据流 在Linux下,当一个用户进程被创建的时候 ...
- jquery+ashx checkbox 单选判断是否true 和 false 传值操作
示例图: html标签代码: <p></p> <label for="checkbox" style="float:left" & ...
- nginx检查报错 error while loading shared libraries: libprofiler.so.0: cannot open shared object file: No such file or directory
在centos7.3上编译安装nginx-1.12.2 启动测试出错 [root@web02 local]# /usr/local/nginx/sbin/nginx -t /usr/local/ngi ...
- mysql:索引原理与慢查询优化
一 索引的原理 1. 索引原理 索引的目的在于提高查询效率,与我们查阅图书所用的目录是一个道理:先定位到章,然后定位到该章下的一个小节,然后找到页数.相似的例子还有:查字典,查火车车次,飞机航班等 本 ...