• <tfoot id='Z450g'></tfoot>
  • <small id='Z450g'></small><noframes id='Z450g'>

    1. <legend id='Z450g'><style id='Z450g'><dir id='Z450g'><q id='Z450g'></q></dir></style></legend>
        • <bdo id='Z450g'></bdo><ul id='Z450g'></ul>
        <i id='Z450g'><tr id='Z450g'><dt id='Z450g'><q id='Z450g'><span id='Z450g'><b id='Z450g'><form id='Z450g'><ins id='Z450g'></ins><ul id='Z450g'></ul><sub id='Z450g'></sub></form><legend id='Z450g'></legend><bdo id='Z450g'><pre id='Z450g'><center id='Z450g'></center></pre></bdo></b><th id='Z450g'></th></span></q></dt></tr></i><div id='Z450g'><tfoot id='Z450g'></tfoot><dl id='Z450g'><fieldset id='Z450g'></fieldset></dl></div>
      1. 将 bind1st 用于通过引用获取参数的方法

        时间:2023-10-06

                <tbody id='pTbdh'></tbody>

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

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

                2. <small id='pTbdh'></small><noframes id='pTbdh'>

                3. 本文介绍了将 bind1st 用于通过引用获取参数的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个这样的结构:

                  struct A {
                      void i(int i) {}
                      void s(string const &s) {}
                  };
                  

                  现在当我尝试这个时:

                  bind1st(mem_fun(&A::i), &a)(0);
                  bind1st(mem_fun(&A::s), &a)("");
                  

                  第一行编译正常,但第二行报错:

                  The first line compiles OK, but the second generates an error:

                  c:program files (x86)microsoft visual studio 10.0vcincludexfunctional(299): error C2535: 'void std::binder1st<_Fn2>::operator ()(const std::basic_string<_Elem,_Traits,_Ax> &) const' : member function already defined or declared
                            with
                            [
                                _Fn2=std::mem_fun1_t<void,A,const std::string &>,
                                _Elem=char,
                                _Traits=std::char_traits<char>,
                                _Ax=std::allocator<char>
                            ]
                            c:program files (x86)microsoft visual studio 10.0vcincludexfunctional(293) : see declaration of 'std::binder1st<_Fn2>::operator ()'
                            with
                            [
                                _Fn2=std::mem_fun1_t<void,A,const std::string &>
                            ]
                            c:worksourcesexception	estexceptionmain.cpp(33) : see reference to class template instantiation 'std::binder1st<_Fn2>' being compiled
                            with
                            [
                                _Fn2=std::mem_fun1_t<void,A,const std::string &>
                            ]
                  

                  可能是什么问题?我该如何解决?

                  What could be the problem? How could I fix it?

                  似乎任何引用参数都有问题.因此,如果我将 i 方法更改为 void i(int &i) {},我会收到类似的错误.

                  It seems that any reference argument is a problem. So if I change the i method to void i(int &i) {} I get a similar error.

                  推荐答案

                  std::bind1st 和 std::bind2nd 不接受接受引用参数的函子,因为它们本身形成对这些参数的引用.你可以

                  std::bind1st and std::bind2nd don't accept functors which take reference arguments, because they themselves form references to these arguments. You can

                  1. 为函数输入使用指针而不是引用
                  2. 使用 boost::bind
                  3. 接受复制字符串的性能成本

                  这篇关于将 bind1st 用于通过引用获取参数的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:为什么编译器选择 bool 而不是 string 来隐式类型转 下一篇:如何从 LPCTSTR 转换为 std::string?

                  相关文章

                  最新文章

                4. <legend id='sLUsr'><style id='sLUsr'><dir id='sLUsr'><q id='sLUsr'></q></dir></style></legend>

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

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