• <tfoot id='cOXoA'></tfoot>
  • <legend id='cOXoA'><style id='cOXoA'><dir id='cOXoA'><q id='cOXoA'></q></dir></style></legend>

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

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

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

        如何使用带有成员函数的 boost 绑定

        How to use boost bind with a member function(如何使用带有成员函数的 boost 绑定)
        <i id='nDPcI'><tr id='nDPcI'><dt id='nDPcI'><q id='nDPcI'><span id='nDPcI'><b id='nDPcI'><form id='nDPcI'><ins id='nDPcI'></ins><ul id='nDPcI'></ul><sub id='nDPcI'></sub></form><legend id='nDPcI'></legend><bdo id='nDPcI'><pre id='nDPcI'><center id='nDPcI'></center></pre></bdo></b><th id='nDPcI'></th></span></q></dt></tr></i><div id='nDPcI'><tfoot id='nDPcI'></tfoot><dl id='nDPcI'><fieldset id='nDPcI'></fieldset></dl></div>

            <tbody id='nDPcI'></tbody>

            • <legend id='nDPcI'><style id='nDPcI'><dir id='nDPcI'><q id='nDPcI'></q></dir></style></legend>

              <tfoot id='nDPcI'></tfoot>

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

                  本文介绍了如何使用带有成员函数的 boost 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码导致 cl.exe 崩溃(MS VS2005).
                  我正在尝试使用 boost bind 创建一个函数来调用 myclass 的方法:

                  The following code causes cl.exe to crash (MS VS2005).
                  I am trying to use boost bind to create a function to a calls a method of myclass:

                  #include "stdafx.h"
                  #include <boost/function.hpp>
                  #include <boost/bind.hpp>
                  #include <functional>
                  
                  class myclass {
                  public:
                      void fun1()       { printf("fun1()
                  ");      }
                      void fun2(int i)  { printf("fun2(%d)
                  ", i); }
                  
                      void testit() {
                          boost::function<void ()>    f1( boost::bind( &myclass::fun1, this ) );
                          boost::function<void (int)> f2( boost::bind( &myclass::fun2, this ) ); //fails
                  
                          f1();
                          f2(111);
                      }
                  };
                  
                  int main(int argc, char* argv[]) {
                      myclass mc;
                      mc.testit();
                      return 0;
                  }
                  

                  我做错了什么?

                  推荐答案

                  改用以下内容:

                  boost::function<void (int)> f2( boost::bind( &myclass::fun2, this, _1 ) );
                  

                  这使用占位符将传递给函数对象的第一个参数转发给函数 - 您必须告诉 Boost.Bind 如何处理这些参数.使用您的表达式,它会尝试将其解释为不带参数的成员函数.
                  见例如此处 或 此处了解常见的使用模式.

                  This forwards the first parameter passed to the function object to the function using place-holders - you have to tell Boost.Bind how to handle the parameters. With your expression it would try to interpret it as a member function taking no arguments.
                  See e.g. here or here for common usage patterns.

                  请注意,VC8s cl.exe 经常因 Boost.Bind 误用而崩溃 - 如果有疑问,请使用带有 gcc 的测试用例,您可能会得到很好的提示,例如模板参数 Bind<如果您通读输出,/em>-internals 会被实例化.

                  Note that VC8s cl.exe regularly crashes on Boost.Bind misuses - if in doubt use a test-case with gcc and you will probably get good hints like the template parameters Bind-internals were instantiated with if you read through the output.

                  这篇关于如何使用带有成员函数的 boost 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='Jkuy9'></tfoot>
                    <legend id='Jkuy9'><style id='Jkuy9'><dir id='Jkuy9'><q id='Jkuy9'></q></dir></style></legend>

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

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

                          <tbody id='Jkuy9'></tbody>

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