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

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

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

        我可以使用 (boost) 绑定函数模板吗?

        Can I use (boost) bind with a function template?(我可以使用 (boost) 绑定函数模板吗?)
      3. <small id='CY8IA'></small><noframes id='CY8IA'>

              <tbody id='CY8IA'></tbody>
            1. <legend id='CY8IA'><style id='CY8IA'><dir id='CY8IA'><q id='CY8IA'></q></dir></style></legend>
            2. <tfoot id='CY8IA'></tfoot>

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

                • 本文介绍了我可以使用 (boost) 绑定函数模板吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以使用 模板>(提升)绑定?

                  Is it possible to bind arguments to a function template with (boost) bind?

                  // Define a template function (just a silly example)
                  template<typename ARG1, typename ARG2>
                  ARG1 FCall2Templ(ARG1 arg1, ARG2 arg2)
                  {
                      return arg1 + arg2;
                  }
                  
                  // try to bind this template function (and call it)
                  ...
                  boost::bind(FCall2Templ<int, int>, 42, 56)(); // This works
                  
                  boost::bind(FCall2Templ, 42, 56)(); // This emits 5 pages of error messages on VS2005
                  // beginning with: error C2780: 
                  //   'boost::_bi::bind_t<_bi::dm_result<MT::* ,A1>::type,boost::_mfi::dm<M,T>,_bi::list_av_1<A1>::type> 
                  //   boost::bind(M T::* ,A1)' : expects 2 arguments - 3 provided
                  
                  boost::bind<int>(FCall2Templ, 42, 56)(); // error C2665: 'boost::bind' : none of the 2 overloads could convert all the argument types
                  

                  想法?

                  推荐答案

                  我不这么认为,只是因为 boost::bind 在这种情况下正在寻找一个函数指针,而不是一个函数模板.当您传入 FCall2Templ 时,编译器会实例化该函数并将其作为函数指针传递.

                  I don't think so, only because boost::bind in this case is looking for a function pointer, not a function template. When you pass in FCall2Templ<int, int>, the compiler instantiates the function and it is passed as a function pointer.

                  但是,您可以使用函子执行以下操作

                  However, you can do the following using a functor

                  struct FCall3Templ {
                  
                    template<typename ARG1, typename ARG2>
                    ARG1 operator()(ARG1 arg1, ARG2 arg2) {
                      return arg1+arg2;
                    }
                  };
                  int main() {
                    boost::bind<int>(FCall3Templ(), 45, 56)();
                    boost::bind<double>(FCall3Templ(), 45.0, 56.0)();
                    return 0;
                  }
                  

                  您必须指定返回类型,因为返回类型与输入相关.如果返回没有变化,那么你可以在模板中添加typedef T result_type,这样bind就可以确定结果是什么

                  You have to specify the return type, since the return type is tied to the inputs. If the return doesn't vary, then you can just add typedef T result_type to the template, so that bind can determine what the result is

                  这篇关于我可以使用 (boost) 绑定函数模板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

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

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

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

                            <tbody id='kerfP'></tbody>