首页 > 编程语言 > 详细

C++primer 7.5.6节练习

时间:2017-08-08 13:34:22      阅读:257      评论:0      收藏:0      [点我收藏+]

练习7.53

 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 
 5 using namespace std;
 6 
 7 class Debug{
 8 public:
 9     constexpr Debug(bool b = true) : hw(b), io(b), other(b) { }
10     constexpr Debug(bool h, bool i, bool o) : hw(h), io(i), other(o) { }
11     constexpr bool any() { return hw || io || other; }
12     void set_io(bool b) { io = b;}
13     void set_hw(bool b) { hw = b;}
14     void set_other(bool b) { hw = b;}
15 private:
16     bool hw;
17     bool io;
18     bool other;
19 
20 }; 
21 
22 
23 int main()
24 {
25     constexpr Debug io_sub(false, true, false);
26 if(io_sub.any())
27   cerr << "print appropriate error messages" << endl;
28 constexpr Debug prod(false);
29 if(prod.any())
30   cerr << "print an error message" << endl;
31 
32     return 0;
33  } 

练习7.54

不应该,因为set_需要将需要的数据成员设置成别的值,因此,不能声明成constexpr

练习7.55

不是,因为string不是一个字面值常量类。

C++primer 7.5.6节练习

原文:http://www.cnblogs.com/wuyinfenghappy/p/7306214.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!