久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <legend id='QqCOg'><style id='QqCOg'><dir id='QqCOg'><q id='QqCOg'></q></dir></style></legend>

      <bdo id='QqCOg'></bdo><ul id='QqCOg'></ul>

    <tfoot id='QqCOg'></tfoot>
    <i id='QqCOg'><tr id='QqCOg'><dt id='QqCOg'><q id='QqCOg'><span id='QqCOg'><b id='QqCOg'><form id='QqCOg'><ins id='QqCOg'></ins><ul id='QqCOg'></ul><sub id='QqCOg'></sub></form><legend id='QqCOg'></legend><bdo id='QqCOg'><pre id='QqCOg'><center id='QqCOg'></center></pre></bdo></b><th id='QqCOg'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QqCOg'><tfoot id='QqCOg'></tfoot><dl id='QqCOg'><fieldset id='QqCOg'></fieldset></dl></div>

    1. <small id='QqCOg'></small><noframes id='QqCOg'>

    2. const 引用的字面初始化

      Literal initialization for const references(const 引用的字面初始化)
        <tbody id='7x7XB'></tbody>
    3. <legend id='7x7XB'><style id='7x7XB'><dir id='7x7XB'><q id='7x7XB'></q></dir></style></legend>

        <i id='7x7XB'><tr id='7x7XB'><dt id='7x7XB'><q id='7x7XB'><span id='7x7XB'><b id='7x7XB'><form id='7x7XB'><ins id='7x7XB'></ins><ul id='7x7XB'></ul><sub id='7x7XB'></sub></form><legend id='7x7XB'></legend><bdo id='7x7XB'><pre id='7x7XB'><center id='7x7XB'></center></pre></bdo></b><th id='7x7XB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='7x7XB'><tfoot id='7x7XB'></tfoot><dl id='7x7XB'><fieldset id='7x7XB'></fieldset></dl></div>
            <bdo id='7x7XB'></bdo><ul id='7x7XB'></ul>

              <small id='7x7XB'></small><noframes id='7x7XB'>

              <tfoot id='7x7XB'></tfoot>

                本文介紹了const 引用的字面初始化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                以下代碼如何在 C++ 中工作?合乎邏輯嗎?

                How does the following code work in C++? Is it logical?

                const int &ref = 9;
                const int &another_ref = ref + 6;
                

                為什么 C++ 允許常量引用的字面初始化,而非常量引用不允許?例如:

                Why does C++ allow literal initialization for const references when the same is not permitted for non-const references? E.g.:

                const int days_of_week = 7;
                int &dof = days_of_week; //error: non const reference to a const object
                

                這可以通過一個事實來解釋,非常量引用可用于更改它所引用的變量的值.因此,C++ 不允許對 const 變量的非常量引用.

                This can be explained by the fact that, a non-const reference can be used to change the value of the variable it is referring to. Hence, C++ does not permit a non-const reference to a const variable.

                這是一個可能的解釋嗎?C++ 不允許:

                Could this be a possible explanation? C++ does not allow:

                int &ref = 7;
                

                因為這不合邏輯,但是:

                Because that is not logical, but:

                const int &ref = 7;
                

                幾乎相當于:

                const int val = 7;
                

                所以常量變量允許字面初始化.

                So literal initialization is permitted for const variables.

                P.S.:我目前正在學習 Lippman 的 C++ Primer.

                P.S.: I'm currently studying Lippman's C++ Primer.

                推薦答案

                所以你可以這樣寫代碼:

                So you can write code like this:

                void f( const string & s ) {
                }
                
                f( "foobar" );
                

                盡管嚴格來說,這里實際發(fā)生的并不是將文字綁定到 const 引用——而是創(chuàng)建了一個臨時字符串對象:

                Although strictly speaking what is actually happening here is not the literal being bound to a const reference - instead a temprary string object is created:

                string( "foobar" );
                

                并且這個無名字符串綁定到引用.

                and this nameless string is bound to the reference.

                請注意,像您這樣做時創(chuàng)建非參數(shù)引用變量實際上很不尋常 - 引用的主要目的是用作函數(shù)參數(shù)和返回值.

                Note that it is actually quite unusual to create non-parameter reference variables as you are doing - the main purpose of references is to serve as function parameters and return values.

                這篇關于const 引用的字面初始化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Why do two functions have the same address?(為什么兩個函數(shù)的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                mixing templates with polymorphism(混合模板與多態(tài)性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
                  <tbody id='0zj4X'></tbody>

              • <tfoot id='0zj4X'></tfoot>
                  <i id='0zj4X'><tr id='0zj4X'><dt id='0zj4X'><q id='0zj4X'><span id='0zj4X'><b id='0zj4X'><form id='0zj4X'><ins id='0zj4X'></ins><ul id='0zj4X'></ul><sub id='0zj4X'></sub></form><legend id='0zj4X'></legend><bdo id='0zj4X'><pre id='0zj4X'><center id='0zj4X'></center></pre></bdo></b><th id='0zj4X'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0zj4X'><tfoot id='0zj4X'></tfoot><dl id='0zj4X'><fieldset id='0zj4X'></fieldset></dl></div>

                    <legend id='0zj4X'><style id='0zj4X'><dir id='0zj4X'><q id='0zj4X'></q></dir></style></legend>

                    <small id='0zj4X'></small><noframes id='0zj4X'>

                      • <bdo id='0zj4X'></bdo><ul id='0zj4X'></ul>

                          主站蜘蛛池模板: av电影手机版 | 一区二区三区观看视频 | 久久久久九九九女人毛片 | 欧美一区二区三区在线观看 | 综合国产第二页 | 日韩精品一区二区三区视频播放 | 婷婷狠狠 | 午夜精品久久久久久久99黑人 | 天天操天天插天天干 | 亚洲在线久久 | 日韩欧美亚洲 | av大片| 精品国产一区二区三区四区在线 | 中文字幕一区二区三区四区五区 | 一级欧美 | 综合久久亚洲 | 伊人网综合在线 | 看a网站| 欧美久久视频 | 亚洲高清在线观看 | 91天堂网| 欧美国产精品一区二区 | 网色 | 欧美一区二区三区的 | 欧美一区二区视频 | 成人深夜福利网站 | 91麻豆精品国产91久久久久久久久 | 美女视频久久 | 免费毛片网站在线观看 | m豆传媒在线链接观看 | 亚洲一区二区三区四区在线观看 | 国产精品射| 国产精品久久久久久久久久妇女 | 精品久久中文 | 午夜国产 | 国产亚洲高清视频 | 日韩久草 | 亚洲一区 中文字幕 | 欧美网址在线观看 | 成人精品国产一区二区4080 | 国产高清视频在线观看播放 |