<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                右值引用可以使我們區分表達式的左值和右值。 C++11引入了右值引用的概念,使得我們把引用與右值進行綁定。使用兩個“取地址符號”: ~~~ int&& rvalue_ref = 99; ~~~ 需要注意的是,只有左值可以付給引用,如: ~~~ int& ref = 9; ~~~ 我們會得到這樣的錯誤: “invalid initialization of non-const reference of type int& from an rvalue of type int” 我們只能這樣做: ~~~ int nine = 9; int& ref = nine; ~~~ 看下面的例子,你會明白的: ~~~ #include <iostream> void f(int& i) { std::cout << "lvalue ref: " << i << "\n"; } void f(int&& i) { std::cout << "rvalue ref: " << i << "\n"; } int main() { int i = 77; f(i); // lvalue ref called f(99); // rvalue ref called f(std::move(i)); // 稍后介紹 return 0; } ~~~ 右值有更隱晦的,記住如果一個表達式的結果是一個暫時的對象,那么這個表達式就是右值,同樣看看代碼: ~~~ #include <iostream> int getValue () { int ii = 10; return ii; } int main() { std::cout << getValue(); return 0; } ~~~ 這里需要注意的是 getValue() 是一個右值。 我們只能這樣做,必須要有const ~~~ const int& val = getValue(); // OK int& val = getValue(); // NOT OK ~~~ 但是C++11中的右值引用允許這樣做: ~~~ const int&& val = getValue(); // OK int&& val = getValue(); // OK ~~~ 現在做一個比較吧: ~~~ void printReference (const int& value) { cout << value; } void printReference (int&& value) { cout << value; } ~~~ 第一個printReference()可以接受參數為左值,也可以接受右值。? 而第二個printReference()只能接受右值引用作為參數。 In other words, by using the rvalue references, we can use function overloading to determine whether function parameters are lvalues or rvalues by having one overloaded function taking an lvalue reference and another taking an rvalue reference. In other words, C++11 introduces a new non-const reference type called an rvalue reference, identified by T&&. This refers to temporaries that are permitted to be modified after they are initialized, which is the cornerstone of move semantics. ~~~ #include <iostream> using namespace std; void printReference (int& value) { cout << "lvalue: value = " << value << endl; } void printReference (int&& value) { cout << "rvalue: value = " << value << endl; } int getValue () { int temp_ii = 99; return temp_ii; } int main() { int ii = 11; printReference(ii); printReference(getValue()); // printReference(99); return 0; } /*---------------------- 輸出 lvalue: value = 11 rvalue: value = 99 ----------------------*/ ~~~
                  <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>

                              哎呀哎呀视频在线观看