<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## const修飾變量 一般用const完全替代C語言的define,且功能更多。用const修飾變量,使之成為常量(或常數) <details> <summary>main.cpp</summary> ``` #include <iostream> #include <string> using namespace std; typedef const double CONSTANT; CONSTANT PI = 3.141592; struct Person { const string name; int age; }; int main() { cout << PI << endl; // 345 Person p = {"cpj", 123}; // 常量無法修改 // p.name="new_cpj"; p.age = 345; cout << p.age << endl; // 345 return 0; } ``` </details> <br/> ## const修飾類的成員函數 在函數后定義 const,使該函數不能修改成員變量,但可修改非成員變量 <details> <summary>main.cpp</summary> ``` #include <iostream> using namespace std; class A { int x; public: void set(int a) { x = a; } // 在函數后定義 const,使該函數不能修改成員變量 void const_set(int a) const { x = a; } }; int main() { A a; a.set(123); // 編譯錯誤 // a.const_set(132); return 0; } ``` </details> <br/> ## mutable與const為敵 用mutable修飾成員變量,可以使該成員變量即使在const成員函數中也能被修改。 <details> <summary>main.cpp</summary> ``` #include <iostream> using namespace std; class A { mutable int x; public: void set(int a) { x = a; } void const_set(int a) const { x = a; } }; int main() { A a; a.set(123); // 可正常賦值 a.const_set(132); return 0; } ``` </details> <br/>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看