不可将布尔变量直接与 TRUE、FALSE 或者 1、0 进行比较

不可将布尔变量直接与 TRUE、FALSE 或者 1、0 进行比较。

根据布尔类型的语义,零值为“假”(记为 FALSE),任何非零值都是“真”(记为 TRUE)。

TRUE 的值究竟是什么并没有统一的标准。例如 Visual C++ 将 TRUE 定义为 1, 而 Visual Basic 则将 TRUE 定义为-1。

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std;
 5 //基类Box
 6 class Box {
 7     int width,height;
 8 public:
 9     void SetWidth(int w) {
10         width=w;
11     }
12     void SetHeight(int h) {
13         height=h;
14     }
15     int GetWidth() {return width;}
16     int GetHeight() {return height;}
17 };
18 //派生类ColoredBox
19 class ColoredBox:public Box
20 {
21     int color;
22 public:
23     void SetColor(int c){
24         color=c;
25     }
26     int GetColor() {return color;}
27 };
28 // 在main()中测试基类和派生类
29 
30 int main(int argc, char** argv) {
31     
32       //声明并使用ColoredBox类的对象
33     ColoredBox cbox;
34     cbox.SetColor(3);       //使用自己的成员函数
35     cbox.SetWidth(150);     //使用基类的成员函数
36     cbox.SetHeight(100);    //使用基类的成员函数
37  
38     cout<<"cbox:"<<endl;
39     cout<<"Color:"<<cbox.GetColor()<<endl;    //使用自己的成员函数
40     cout<<"Width:"<<cbox.GetWidth()<<endl;   //使用基类的成员函数
41     cout<<"Height:"<<cbox.GetHeight()<<endl;  //使用基类的成员函数
42     //cout<<cbox.width; Error!  
43     return 0;
44 }

 

转载于:https://www.cnblogs.com/borter/p/9413467.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值