C++primer 7.5.6節練習

來源:互聯網
上載者:User

標籤:prim   不能   blog   logs   public   expr   log   ret   other   

練習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節練習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.