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

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

  1. <tfoot id='mQqZX'></tfoot>

  2. <small id='mQqZX'></small><noframes id='mQqZX'>

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

      <legend id='mQqZX'><style id='mQqZX'><dir id='mQqZX'><q id='mQqZX'></q></dir></style></legend>

      std::to_string - 多個重載函數(shù)的實(shí)例與參數(shù)列表匹配

      std::to_string - more than instance of overloaded function matches the argument list(std::to_string - 多個重載函數(shù)的實(shí)例與參數(shù)列表匹配)
        <legend id='WmwNK'><style id='WmwNK'><dir id='WmwNK'><q id='WmwNK'></q></dir></style></legend>
              <tbody id='WmwNK'></tbody>
          • <small id='WmwNK'></small><noframes id='WmwNK'>

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

              1. <tfoot id='WmwNK'></tfoot>

                <i id='WmwNK'><tr id='WmwNK'><dt id='WmwNK'><q id='WmwNK'><span id='WmwNK'><b id='WmwNK'><form id='WmwNK'><ins id='WmwNK'></ins><ul id='WmwNK'></ul><sub id='WmwNK'></sub></form><legend id='WmwNK'></legend><bdo id='WmwNK'><pre id='WmwNK'><center id='WmwNK'></center></pre></bdo></b><th id='WmwNK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WmwNK'><tfoot id='WmwNK'></tfoot><dl id='WmwNK'><fieldset id='WmwNK'></fieldset></dl></div>
                本文介紹了std::to_string - 多個重載函數(shù)的實(shí)例與參數(shù)列表匹配的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

                counter 是一個 int

                void SentryManager::add(std::string name,std::shared_ptr){name = name + std::to_string(counter);}

                阻止此錯誤的最佳方法是什么?當(dāng)我懶惰時,我只是制作了 int long long(或其他東西),但我相信有更好的方法來解決這個問題.

                錯誤信息:

                sentrymanager.cpp(8):錯誤 C2668:'std::to_string':對重載函數(shù)的調(diào)用不明確

                我使用的是 Visual C++ 2010 Express.

                解決方案

                在 VC++ 2010 中,std::to_string 的三個重載需要 long long>unsigned long longlong double,分別——很明顯 int 不是這些,沒有一種轉(zhuǎn)換比另一種更好(demo),因此無法隱式/明確地進(jìn)行轉(zhuǎn)換.

                就真正的 C++11 支持而言,這是 VC++ 2010 標(biāo)準(zhǔn)庫實(shí)現(xiàn)的一個失敗——C++11 標(biāo)準(zhǔn)本身實(shí)際上要求 九個 重載std::to_string ([string.conversions]/7):

                <塊引用>

                string to_string(int val);字符串 to_string(unsigned val);字符串 to_string(long val);字符串 to_string(unsigned long val);字符串 to_string(long long val);字符串 to_string(unsigned long long val);字符串 to_string(float val);字符串 to_string(double val);字符串 to_string(long double val);

                如果所有這些重載都存在,你顯然不會有這個問題;然而,VC++ 2010 并不是基于實(shí)際的 C++11 標(biāo)準(zhǔn)(在發(fā)布時還不存在),而是基于 N3000(來自2009),它調(diào)用對于這些額外的重載.因此,在這里責(zé)怪 VC++ 太苛刻了...

                無論如何,對于少數(shù)調(diào)用,使用強(qiáng)制轉(zhuǎn)換自己解決歧義并沒有錯:

                void SentryManager::add(std::string& name, std::shared_ptr) {名稱 += std::to_string(static_cast(counter));}

                或者,如果您的代碼庫中大量使用 std::to_string,請編寫一些包裝器并改用它們——這樣,就不需要調(diào)用站點(diǎn)轉(zhuǎn)換:

                #include #include <字符串>模板排隊(duì)類型名稱 std::enable_if<std::is_integral<T>::value &&std::is_signed::value, std::string>::typeto_string(T const val) {返回 std::to_string(static_cast(val));}模板排隊(duì)類型名稱 std::enable_if<std::is_integral<T>::value &&std::is_unsigned::value, std::string>::typeto_string(T const val) {返回 std::to_string(static_cast(val));}模板內(nèi)聯(lián)類型名 std::enable_if::value, std::string>::typeto_string(T const val) {返回 std::to_string(static_cast(val));}//...void SentryManager::add(std::string& name, std::shared_ptr<Sentry>) {名稱 += to_string(counter);}

                <小時>

                以上SFINAE的使用方式無法檢測VC++ 2010是成功還是失??;如果失敗,以下內(nèi)容——使用標(biāo)簽調(diào)度而不是 SFINAE——應(yīng)該是可編譯的(如果可能不太清楚):

                #include #include <字符串>命名空間細(xì)節(jié){模板//is_float is_unsigned內(nèi)聯(lián) std::string to_string(T const val, std::false_type, std::false_type) {返回 std::to_string(static_cast(val));}模板//is_float is_unsigned內(nèi)聯(lián) std::string to_string(T const val, std::false_type, std::true_type) {返回 std::to_string(static_cast(val));}模板//is_float內(nèi)聯(lián) std::string to_string(T const val, std::true_type, _) {返回 std::to_string(static_cast(val));}}模板內(nèi)聯(lián) std::string to_string(T const val) {return detail::to_string(val, std::is_floating_point(), std::is_unsigned());}

                counter is an int

                void SentryManager::add(std::string name,std::shared_ptr<Sentry>){
                    name = name + std::to_string(counter);
                }
                

                What would be the best way to stop this error? When I was being lazy I just made the int long long (or something), but I'm sure there is a better way of solving this.

                Error message:

                sentrymanager.cpp(8): error C2668: 'std::to_string' : ambiguous call to overloaded function
                

                I am using Visual C++ 2010 Express.

                解決方案

                In VC++ 2010 there are three overloads of std::to_string that take long long, unsigned long long, and long double, respectively – clearly int is none of these, and no one conversion is better than another (demo), so the conversion cannot be done implicitly/unambiguously.

                In terms of real C++11 support, this is a failing on the part of VC++ 2010's standard library implementation – the C++11 standard itself actually calls for nine overloads of std::to_string ([string.conversions]/7):

                string to_string(int val);
                string to_string(unsigned val);
                string to_string(long val);
                string to_string(unsigned long val);
                string to_string(long long val);
                string to_string(unsigned long long val);
                string to_string(float val);
                string to_string(double val);
                string to_string(long double val);
                

                Had all of these overloads been present, you obviously wouldn't have this problem; however, VC++ 2010 wasn't based on the actual C++11 standard (which did not yet exist at the time of its release), but rather on N3000 (from 2009), which does not call for these additional overloads. Consequently, it's harsh to blame VC++ too much here...

                In any case, for only a handful of calls, there's nothing wrong with using a cast to resolve the ambiguity yourself:

                void SentryManager::add(std::string& name, std::shared_ptr<Sentry>) {
                    name += std::to_string(static_cast<long long>(counter));
                }
                

                Or, if there's heavy usage of std::to_string in your codebase, write a few wrappers and use those instead – this way, no call-site casting is needed:

                #include <type_traits>
                #include <string>
                
                template<typename T>
                inline
                typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, std::string>::type
                to_string(T const val) {
                    return std::to_string(static_cast<long long>(val));
                }
                
                template<typename T>
                inline
                typename std::enable_if<std::is_integral<T>::value && std::is_unsigned<T>::value, std::string>::type
                to_string(T const val) {
                    return std::to_string(static_cast<unsigned long long>(val));
                }
                
                template<typename T>
                inline typename std::enable_if<std::is_floating_point<T>::value, std::string>::type
                to_string(T const val) {
                    return std::to_string(static_cast<long double>(val));
                }
                
                // ...
                
                void SentryManager::add(std::string& name, std::shared_ptr<Sentry>) {
                    name += to_string(counter);
                }
                


                I can't check whether VC++ 2010 succeeds or fails with the above usage of SFINAE; if it fails, the following – using tag dispatch instead of SFINAE – should be compilable (if potentially less clear):

                #include <type_traits>
                #include <string>
                
                namespace detail {
                    template<typename T>                   // is_float         is_unsigned
                    inline std::string to_string(T const val, std::false_type, std::false_type) {
                        return std::to_string(static_cast<long long>(val));
                    }
                
                    template<typename T>                   // is_float         is_unsigned
                    inline std::string to_string(T const val, std::false_type, std::true_type) {
                        return std::to_string(static_cast<unsigned long long>(val));
                    }
                
                    template<typename T, typename _>       // is_float
                    inline std::string to_string(T const val, std::true_type, _) {
                        return std::to_string(static_cast<long double>(val));
                    }
                }
                
                template<typename T>
                inline std::string to_string(T const val) {
                    return detail::to_string(val, std::is_floating_point<T>(), std::is_unsigned<T>());
                }
                

                這篇關(guān)于std::to_string - 多個重載函數(shù)的實(shí)例與參數(shù)列表匹配的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Why do two functions have the same address?(為什么兩個函數(shù)的地址相同?)
                Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                mixing templates with polymorphism(混合模板與多態(tài)性)
                When should I use the keyword quot;typenamequot; when using templates(我什么時候應(yīng)該使用關(guān)鍵字“typename?使用模板時)
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫)
                gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
                <i id='nXilA'><tr id='nXilA'><dt id='nXilA'><q id='nXilA'><span id='nXilA'><b id='nXilA'><form id='nXilA'><ins id='nXilA'></ins><ul id='nXilA'></ul><sub id='nXilA'></sub></form><legend id='nXilA'></legend><bdo id='nXilA'><pre id='nXilA'><center id='nXilA'></center></pre></bdo></b><th id='nXilA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='nXilA'><tfoot id='nXilA'></tfoot><dl id='nXilA'><fieldset id='nXilA'></fieldset></dl></div>

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

                    <small id='nXilA'></small><noframes id='nXilA'>

                        <tbody id='nXilA'></tbody>

                      1. <tfoot id='nXilA'></tfoot>
                        • <legend id='nXilA'><style id='nXilA'><dir id='nXilA'><q id='nXilA'></q></dir></style></legend>
                          主站蜘蛛池模板: 国产精品欧美日韩 | 精品国产31久久久久久 | 免费成人高清在线视频 | 91免费在线 | 国产一区二区三区视频 | www312aⅴ欧美在线看 | 91日韩在线 | 91精品国产综合久久精品 | 古装三级在线播放 | 99re在线视频 | 日韩精品在线一区 | 美女天天操| 成人av在线播放 | 嫩草最新网址 | 国产一区二区精品自拍 | aaaa一级毛片| 国产91中文 | 艹逼网 | 欧美一a | 亚洲精选一区二区 | 日韩中文字幕一区二区 | 亚洲男人的天堂网站 | 97精品超碰一区二区三区 | 国产成人在线视频免费观看 | 日韩精品成人 | 欧美性猛交| 亚洲一区亚洲二区 | 久久精品国产久精国产 | 中文字幕第一页在线 | 国产在线不卡 | 亚洲日韩视频 | 日本一区精品 | 亚洲国产成人在线观看 | www.99re5.com| 成人精品国产 | 国产真实精品久久二三区 | 久久av一区| 国产做a爱片久久毛片 | 91精品国产综合久久久久久丝袜 | 97超碰人人 | 涩涩操 |