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

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

    • <bdo id='nggEd'></bdo><ul id='nggEd'></ul>
    1. <small id='nggEd'></small><noframes id='nggEd'>

      <tfoot id='nggEd'></tfoot>

      如何使用 bind1st 和 bind2nd?

      How to use bind1st and bind2nd?(如何使用 bind1st 和 bind2nd?)
      <tfoot id='WM7QM'></tfoot>
      <i id='WM7QM'><tr id='WM7QM'><dt id='WM7QM'><q id='WM7QM'><span id='WM7QM'><b id='WM7QM'><form id='WM7QM'><ins id='WM7QM'></ins><ul id='WM7QM'></ul><sub id='WM7QM'></sub></form><legend id='WM7QM'></legend><bdo id='WM7QM'><pre id='WM7QM'><center id='WM7QM'></center></pre></bdo></b><th id='WM7QM'></th></span></q></dt></tr></i><div id='WM7QM'><tfoot id='WM7QM'></tfoot><dl id='WM7QM'><fieldset id='WM7QM'></fieldset></dl></div>
          <bdo id='WM7QM'></bdo><ul id='WM7QM'></ul>

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

                <tbody id='WM7QM'></tbody>
            • <small id='WM7QM'></small><noframes id='WM7QM'>

              1. 本文介绍了如何使用 bind1st 和 bind2nd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想学习如何使用绑定函数.这是一个想法:我有这个需要参数的函数:

                I would like to learn how to use binding functions. Here is the idea: I have this function which takes to parameters:

                void print_i(int t, std::string separator)
                {
                        std::cout << t << separator;
                }
                

                我想做:

                std::vector<int> elements;
                // ...
                for_each(elements.begin(), elements.end(), std::bind2nd(print_i, '
                '));
                

                但它不起作用!

                这是我得到的:

                /usr/include/c++/4.3/backward/binders.h: In instantiation of ‘std::binder2nd<void ()(int, std::string)>’:
                main.cpp:72:   instantiated from here
                /usr/include/c++/4.3/backward/binders.h:138: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/backward/binders.h:141: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/backward/binders.h:145: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/backward/binders.h:149: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/backward/binders.h:155: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/backward/binders.h:140: error: field ‘std::binder2nd<void ()(int, std::string)>::op’ invalidly declared function type
                /usr/include/c++/4.3/backward/binders.h: In function ‘std::binder2nd<_Operation> std::bind2nd(const _Operation&, const _Tp&) [with _Operation = void ()(int, std::string), _Tp = char]’:
                main.cpp:72:   instantiated from here
                /usr/include/c++/4.3/backward/binders.h:164: error: ‘void ()(int, std::string)’ is not a class, struct, or union type
                /usr/include/c++/4.3/bits/stl_algo.h: In function ‘_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, _Funct = std::binder2nd<void ()(int, std::string)>]’:
                main.cpp:72:   instantiated from here
                /usr/include/c++/4.3/bits/stl_algo.h:3791: error: no match for call to ‘(std::binder2nd<void ()(int, std::string)>) (int&)’
                make: *** [all] Error 1
                

                我可以使用函子,但使用绑定会更快.

                I could use functor, but it is quicker to use binding.

                谢谢!

                推荐答案

                bind2nd 的参数必须是 AdaptableBinaryFunction.一个普通的二元函数不满足这个要求(一个可适应的函数需要 typedefs 作为它的返回和参数类型,一个普通的函数类型不提供任何 typedefs).您可以使用 std::bind 其中无论如何可能是更好的选择.

                The argument to bind2nd must be an AdaptableBinaryFunction. A plain binary function does not fulfill this requirement (an adaptable function required typedefs for its return and argument types, a plain function type does not provide any typedefs). You could use std::bind which is probably the better choice anyway.

                这篇关于如何使用 bind1st 和 bind2nd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Is Type(::x); valid?(是类型(::x);有效的?)
                Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
                  <tfoot id='5kNNu'></tfoot>

                  • <bdo id='5kNNu'></bdo><ul id='5kNNu'></ul>

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

                            <tbody id='5kNNu'></tbody>
                        1. <small id='5kNNu'></small><noframes id='5kNNu'>