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

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

        <bdo id='GV09Q'></bdo><ul id='GV09Q'></ul>
      <tfoot id='GV09Q'></tfoot>

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

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

      在成員函數(shù)內(nèi)的 lambda 捕獲列表中使用成員變量

      Using member variable in lambda capture list inside a member function(在成員函數(shù)內(nèi)的 lambda 捕獲列表中使用成員變量)

        <tbody id='jtgd2'></tbody>

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

                <bdo id='jtgd2'></bdo><ul id='jtgd2'></ul>
              • <small id='jtgd2'></small><noframes id='jtgd2'>

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

              • 本文介紹了在成員函數(shù)內(nèi)的 lambda 捕獲列表中使用成員變量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時送ChatGPT賬號..

                以下代碼使用 gcc 4.5.1 編譯但不適用于 VS2010 SP1:

                The following code compiles with gcc 4.5.1 but not with VS2010 SP1:

                #include <iostream>
                #include <vector>
                #include <map>
                #include <utility>
                #include <set>
                #include <algorithm>
                
                using namespace std;
                class puzzle
                {
                        vector<vector<int>> grid;
                        map<int,set<int>> groups;
                public:
                        int member_function();
                };
                
                int puzzle::member_function()
                {
                        int i;
                        for_each(groups.cbegin(),groups.cend(),[grid,&i](pair<int,set<int>> group){
                                i++;
                                cout<<i<<endl;
                        });
                }
                int main()
                {
                        return 0;
                }
                

                這是錯誤:

                error C3480: 'puzzle::grid': a lambda capture variable must be from an enclosing function scope
                warning C4573: the usage of 'puzzle::grid' requires the compiler to capture 'this' but the current default capture mode does not allow it
                

                所以,

                1> 哪個編譯器是對的?

                1> which compiler is right?

                2> 如何在 VS2010 的 lambda 中使用成員變量?

                2> How can I use member variables inside a lambda in VS2010?

                推薦答案

                我相信 VS2010 這次是正確的,我會檢查我是否有方便的標(biāo)準(zhǔn),但目前我沒有.

                I believe VS2010 to be right this time, and I'd check if I had the standard handy, but currently I don't.

                現(xiàn)在,就像錯誤消息所說的那樣:您無法捕獲 lambda 封閉范圍之外的內(nèi)容.? grid 不在封閉范圍內(nèi),但是 this 是(在成員函數(shù)中,對 grid 的每次訪問實際上都是作為 this->grid 發(fā)生的).對于您的用例,捕獲 this 有效,因為您將立即使用它并且您不想復(fù)制 grid

                Now, it's exactly like the error message says: You can't capture stuff outside of the enclosing scope of the lambda.? grid is not in the enclosing scope, but this is (every access to grid actually happens as this->grid in member functions). For your usecase, capturing this works, since you'll use it right away and you don't want to copy the grid

                auto lambda = [this](){ std::cout << grid[0][0] << "
                "; }
                

                但是,如果您想要存儲網(wǎng)格并復(fù)制它以供以后訪問,而您的 puzzle 對象可能已經(jīng)被銷毀,則您需要制作一個中間的本地副本:

                If however, you want to store the grid and copy it for later access, where your puzzle object might already be destroyed, you'll need to make an intermediate, local copy:

                vector<vector<int> > tmp(grid);
                auto lambda = [tmp](){}; // capture the local copy per copy
                

                <小時>

                ? 我正在簡化 - 谷歌搜索達到范圍"或參閱第 5.1.2 節(jié)了解所有血腥細節(jié).


                ? I'm simplifying - Google for "reaching scope" or see §5.1.2 for all the gory details.

                這篇關(guān)于在成員函數(shù)內(nèi)的 lambda 捕獲列表中使用成員變量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

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

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

                    <tfoot id='rvsaL'></tfoot>
                        <bdo id='rvsaL'></bdo><ul id='rvsaL'></ul>
                        • <small id='rvsaL'></small><noframes id='rvsaL'>

                        • 主站蜘蛛池模板: 中文字幕国产 | 欧美精品日韩精品国产精品 | 亚洲狠狠丁香婷婷综合久久久 | 欧美一级视频在线观看 | 黄色片亚洲 | 国产精品一区二区视频 | 精品视频亚洲 | 亚洲一区二区久久久 | 男女羞羞视频在线观看 | 欧美一级视频免费看 | 日韩av一区二区在线 | 日韩一级黄色片 | 成人超碰| 亚洲性综合网 | 成人永久免费 | 亚洲免费观看视频网站 | 中文字幕亚洲专区 | 日本电影网站 | 狠狠躁18三区二区一区 | 国产精品视频网站 | 拍真实国产伦偷精品 | 激情五月综合 | 天天爽天天操 | 免费视频99 | 在线免费国产视频 | 亚洲精品一区二区三区 | 中文字幕av在线一二三区 | 中国大陆高清aⅴ毛片 | 国产精品美女久久久久久免费 | 麻豆久久精品 | 国产免费看 | 欧美激情一区二区三级高清视频 | 中文字幕 亚洲一区 | 高清国产午夜精品久久久久久 | 亚洲国产aⅴ成人精品无吗 综合国产在线 | 中文字幕高清视频 | 久久国产精品-国产精品 | 亚洲第一成年免费网站 | 国产精品国产三级国产a | 一级毛片色一级 | 国产精品视频一区二区三 |