不可将布尔变量直接与 TRUE、FALSE 或者 1、0 进行比较
不可将布尔变量直接与 TRUE、FALSE 或者 1、0 进行比较。
根据布尔类型的语义,零值为“假”(记为 FALSE),任何非零值都是“真”(记为 TRUE)。
TRUE 的值究竟是什么并没有统一的标准。例如 Visual C++ 将 TRUE 定义为 1, 而 Visual Basic 则将 TRUE 定义为-1。
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
//基类Box
class Box {
int width,height;
public:
void SetWidth(int w) {
width=w;
}
void SetHeight(int h) {
height=h;
}
int GetWidth() {return width;}
int GetHeight() {return height;}
};
//派生类ColoredBox
class ColoredBox:public Box
{
int color;
public:
void SetColor(int c){
color=c;
}
int GetColor() {return color;}
};
// 在main()中测试基类和派生类
int main(int argc, char** argv) {
//声明并使用ColoredBox类的对象
ColoredBox cbox;
cbox.SetColor(); //使用自己的成员函数
cbox.SetWidth(); //使用基类的成员函数
cbox.SetHeight(); //使用基类的成员函数
cout<<"cbox:"<<endl;
cout<<"Color:"<<cbox.GetColor()<<endl; //使用自己的成员函数
cout<<"Width:"<<cbox.GetWidth()<<endl; //使用基类的成员函数
cout<<"Height:"<<cbox.GetHeight()<<endl; //使用基类的成员函数
//cout<<cbox.width; Error!
return ;
}
不可将布尔变量直接与 TRUE、FALSE 或者 1、0 进行比较的更多相关文章
- console.log(([])?true:false); console.log(([]==false?true:false)); console.log(({}==false)?true:false)
下面是题目的类型转换结果: Boolean([]); //true Number([]); //0 Number({}); // NaN Number(false); //0 因此: console. ...
- Python web后端接收到的json数据有前端格式的布尔值 true false
最近在后端处理前端传过来的json数据,发现,因为数据是各种数据格式的嵌套,使用json.loads(),无法将内层的数据转换为原来格式的数据,所以需要使用eval( )函数进行转换,但是如果数据含有 ...
- 大爽Python入门教程 3-1 布尔值: True, False
大爽Python入门公开课教案 点击查看教程总目录 1 布尔值介绍 从判断说起 回顾第一章介绍的简单的判断 >>> x = 10 >>> if x > 5: ...
- Java开发笔记(十二)布尔变量论道与或非
在编程语言的设计之初,它们除了可以进行数学计算,还常常用于逻辑推理和条件判断.为了实现逻辑判断的功能,Java引入了一种布尔类型boolean,用来表示“真”和“假”.该类型的变量只允许两个取值,即t ...
- c++ 中 BOOL与bool TRUE与true FALSE与false 区别
转自:http://blog.chinaunix.net/uid-28458801-id-3941112.html FALSE/TRUE与false/true的区别 1.FALSE/TRUE与fa ...
- 不可将布尔值直接与true或者1进行比较
不可将布尔值直接与TRUR.FALSE或者"0"."1"进行比较. 根据布尔值的定义,零值为"假"(记为FALSE),任何非零值都是&quo ...
- 简写代码:当变量为false时['',false,null,undefined,0,NaN]时,返回默认值
当变量为'',false,null,undefined,0,NaN时,返回默认值 var a='' a || 'hello world' "hello world" var a ...
- if 条件的 true / false 及 select 的值
if 条件的 true / false 任何不是 false, undefined, null, 0, NaN 的值,或一个空字符串('')在作为条件语句进行测试时实际返回true,因此您可以简单地使 ...
- localStorage存的值如果有true,false,需要注意了。
把一个全局变量存到localStorage里面 isSupport是 true false; window.localStorage && window.localStorage.s ...
随机推荐
- ASP.NET自定义Web服务器控件-DropDownList/Select下拉列表控件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; usin ...
- PHPEXCEL导出excel表格中长数字文本自动转为科学计数法的解决办法
方法一:前面加空格 $objActSheet->setCellValue('A1', ' '.'330602198804224688'); 方法二: $objActSheet->setCe ...
- cocos2dx 3.3 getParentToNodeTransform bug
cocos2dx 3.3中getParentToNodeTransform实现如下: const Mat4& Node::getParentToNodeTransform() const { ...
- Jenkins 使用学习笔记
3.1 Jenkins安装 2 3.1.1 Jenkins下载 2 3.1.2 Jenkins 安装 2 3.1.3 Jenkins 目录结构 3 3. ...
- controller与requestmapping
使用@controller定义controllersSpring mvc将特定url的请求分发到controller类来进行处理在spring 3.0中,通过@controller标注即可将class ...
- SVN 版本服务器搭配全过程详解(含服务端、客户端)
1.为什么要用VisualSVN Server,而不用Subversion? 回答: 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Serve ...
- 8个非常实用的PHP安全函数,你知道几个?
原文:Useful functions to provide secure PHP application 译文:实用的PHP安全函数 译者:dwqs 安全是编程很重要的一个方面.在不论什么一种编程语 ...
- JAVA文件转换为Base64
JAVA文件转换为Base64 import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream ...
- 每日英语:Why Are Fractions Key To Future Math Success?
Many students cruise along just fine in math until fourth grade or so. Then, they hit a wall -- frac ...
- 解决老是提示找不到Mapper文件无法执行定义的方法问题!
尼玛,被mybatis的*Mapper.xml文件害惨了!整整两天都在围绕这个问题转圈! 先看问题长啥样吧!下面是通过逆向工程生成的Mapper.xml文件,包路径什么的都没有错! 但是每次调用Map ...