<tfoot id='XSrOg'></tfoot>

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

      1. <i id='XSrOg'><tr id='XSrOg'><dt id='XSrOg'><q id='XSrOg'><span id='XSrOg'><b id='XSrOg'><form id='XSrOg'><ins id='XSrOg'></ins><ul id='XSrOg'></ul><sub id='XSrOg'></sub></form><legend id='XSrOg'></legend><bdo id='XSrOg'><pre id='XSrOg'><center id='XSrOg'></center></pre></bdo></b><th id='XSrOg'></th></span></q></dt></tr></i><div id='XSrOg'><tfoot id='XSrOg'></tfoot><dl id='XSrOg'><fieldset id='XSrOg'></fieldset></dl></div>
      2. <legend id='XSrOg'><style id='XSrOg'><dir id='XSrOg'><q id='XSrOg'></q></dir></style></legend>

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

        Lambda 的显式返回类型

        时间:2023-10-06
          <tbody id='rlIWP'></tbody>

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

                  <tfoot id='rlIWP'></tfoot>

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

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

                1. 本文介绍了Lambda 的显式返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我尝试编译此代码 (VS2010) 时,出现以下错误:错误 C3499:已被指定为具有 void 返回类型的 lambda 无法返回值

                  When I try and compile this code (VS2010) I am getting the following error: error C3499: a lambda that has been specified to have a void return type cannot return a value

                  void DataFile::removeComments()
                  {
                    string::const_iterator start, end;
                    boost::regex expression("^\s?#");
                    boost::match_results<std::string::const_iterator> what;
                    boost::match_flag_type flags = boost::match_default;
                    // Look for lines that either start with a hash (#)
                    // or have nothing but white-space preceeding the hash symbol
                    remove_if(rawLines.begin(), rawLines.end(), [&expression, &start, &end, &what, &flags](const string& line)
                    {
                      start = line.begin();
                      end = line.end();
                      bool temp = boost::regex_search(start, end, what, expression, flags);
                      return temp;
                    });
                  }
                  

                  我如何指定 lambda 具有void"返回类型.此外,如何指定 lambda 具有bool"返回类型?

                  How did I specify that the lambda has a 'void' return type. More-over, how do I specify that the lambda has 'bool' return type?

                  更新

                  以下编译.有人可以告诉我为什么可以编译而另一个不能吗?

                  The following compiles. Can someone please tell me why that compiles and the other does not?

                  void DataFile::removeComments()
                  {
                    boost::regex expression("^(\s+)?#");
                    boost::match_results<std::string::const_iterator> what;
                    boost::match_flag_type flags = boost::match_default;
                    // Look for lines that either start with a hash (#)
                    // or have nothing but white-space preceeding the hash symbol
                    rawLines.erase(remove_if(rawLines.begin(), rawLines.end(), [&expression, &what, &flags](const string& line)
                    { return boost::regex_search(line.begin(), line.end(), what, expression, flags); }));
                  }
                  

                  推荐答案

                  您可以使用 -> 显式指定 lambda 的返回类型.在参数列表后输入:

                  []() -> Type { }
                  

                  但是,如果 lambda 有一个语句并且该语句是 return 语句(并且它返回一个表达式),则编译器可以从该返回表达式的类型推导出返回类型.您的 lambda 中有多个语句,因此它不会推断类型.

                  However, if a lambda has one statement and that statement is a return statement (and it returns an expression), the compiler can deduce the return type from the type of that one returned expression. You have multiple statements in your lambda, so it doesn't deduce the type.

                  这篇关于Lambda 的显式返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:查找“死代码"在大型 C++ 遗留应用程序中 下一篇:在 Visual Studio 中的项目之间共享预编译头文件

                  相关文章

                  最新文章

                      <legend id='MxF20'><style id='MxF20'><dir id='MxF20'><q id='MxF20'></q></dir></style></legend>
                        <bdo id='MxF20'></bdo><ul id='MxF20'></ul>
                    1. <tfoot id='MxF20'></tfoot>

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

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