久久久久久久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 - 多個(gè)重載函數(shù)的實(shí)例與參數(shù)列表匹配

      std::to_string - more than instance of overloaded function matches the argument list(std::to_string - 多個(gè)重載函數(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 - 多個(gè)重載函數(shù)的實(shí)例與參數(shù)列表匹配的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                限時(shí)送ChatGPT賬號(hào)..

                counter 是一個(gè) int

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

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

                錯(cuò)誤信息:

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

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

                解決方案

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

                就真正的 C++11 支持而言,這是 VC++ 2010 標(biāo)準(zhǔn)庫(kù)實(shí)現(xiàn)的一個(gè)失敗——C++11 標(biāo)準(zhǔn)本身實(shí)際上要求 九個(gè) 重載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);

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

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

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

                或者,如果您的代碼庫(kù)中大量使用 std::to_string,請(qǐng)編寫一些包裝器并改用它們——這樣,就不需要調(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);}

                <小時(shí)>

                以上SFINAE的使用方式無(wú)法檢測(cè)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 - 多個(gè)重載函數(shù)的實(shí)例與參數(shù)列表匹配的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Why do two functions have the same address?(為什么兩個(gè)函數(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(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫(kù))
                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>
                          主站蜘蛛池模板: 中国黄色1级片 | 黄色一级在线观看 | 91日韩欧美 | 欧美日韩第一区 | av大片在线观看 | 丰满少妇高潮在线观看 | 国产精品视频免费在线观看 | 成人黄色免费视频 | 两性午夜视频 | 国产精品免费一区 | 在线观看国产小视频 | 天天综合永久入口 | 在线观看日韩av | 午夜av在线播放 | 国产精品五区 | 国产寡妇亲子伦一区二区三区四区 | 日韩三级一区 | 最新中文字幕在线观看 | av噜噜| 天天干网站 | 国产欧美一区二区三区在线看蜜臀 | 99re在线观看视频 | 亚洲综合在线视频 | 亚洲7777| 国产日韩亚洲 | 黄色国产在线观看 | 一区在线观看视频 | 国产精品一区在线播放 | 国产福利视频在线观看 | 午夜在线国语中文字幕视频 | 国产一级黄色大片 | 在线观看黄色片 | 青青操影院 | 亚洲天堂免费视频 | 黄色网址在线播放 | 激情小说在线视频 | 中文精品一区 | 香蕉综合网 | 精品免费视频 | 亚洲日本中文字幕 | 丰满女人裸体淫交 |