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

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

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

    2. <tfoot id='j060e'></tfoot>

    3. <small id='j060e'></small><noframes id='j060e'>

        lambdas 需要捕获“this"来调用静态成员函数?

        lambdas require capturing #39;this#39; to call static member function?(lambdas 需要捕获“this来调用静态成员函数?)
        • <small id='Z1Uoc'></small><noframes id='Z1Uoc'>

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

          <tfoot id='Z1Uoc'></tfoot>

            • <bdo id='Z1Uoc'></bdo><ul id='Z1Uoc'></ul>

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

                1. 本文介绍了lambdas 需要捕获“this"来调用静态成员函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于以下代码:

                  struct B
                  {
                      void g()
                      {
                          []() { B::f(); }();
                      }
                  
                      static void f();
                  };
                  

                  g++ 4.6 给出错误:

                  g++ 4.6 gives the error:

                  test.cpp:在 lambda 函数中:
                  test.cpp:44:21: 错误:此 lambda 函数未捕获this"

                  test.cpp: In lambda function:
                  test.cpp:44:21: error: 'this' was not captured for this lambda function

                  (有趣的是,g++ 4.5 编译代码很好).

                  (Interestingly, g++ 4.5 compiles the code fine).

                  这是 g++ 4.6 中的错误,还是真的有必要捕获this"参数才能调用静态成员函数?我不明白为什么会这样,我什至用 B:: 限定了调用.

                  Is this a bug in g++ 4.6, or is it really necessary to capture the 'this' parameter to be able to call a static member function? I don't see why it should be, I even qualified the call with B::.

                  推荐答案

                  我同意,它应该编译得很好.对于修复(如果您还不知道),只需添加引用捕获,它就会在 gcc 4.6 上正常编译

                  I agree, it should compile just fine. For the fix (if you didn't know already), just add the reference capture and it will compile fine on gcc 4.6

                  struct B
                  {
                      void g()
                      {
                          [&]() { B::f(); }();
                      }
                  
                      static void f() { std::cout << "Hello World" << std::endl; };
                  };
                  

                  这篇关于lambdas 需要捕获“this"来调用静态成员函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                    <tfoot id='zyMmw'></tfoot>

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

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

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