<bdo id='2lKXM'></bdo><ul id='2lKXM'></ul>

<small id='2lKXM'></small><noframes id='2lKXM'>

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

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

    2. std::bind 重载解析

      时间:2023-10-18

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

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

              <tbody id='DwgU4'></tbody>
            <tfoot id='DwgU4'></tfoot>

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

                <bdo id='DwgU4'></bdo><ul id='DwgU4'></ul>
              • 本文介绍了std::bind 重载解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                以下代码运行正常

                #include <functional>
                
                using namespace std;
                using namespace std::placeholders;
                
                class A
                {
                  int operator()( int i, int j ) { return i - j; }
                };
                
                A a;
                auto aBind = bind( &A::operator(), ref(a), _2, _1 );
                

                这个没有

                #include <functional>
                
                using namespace std;
                using namespace std::placeholders;
                
                class A
                {
                  int operator()( int i, int j ) { return i - j; }
                  int operator()( int i ) { return -i; }
                };
                
                A a;
                auto aBind = bind( &A::operator(), ref(a), _2, _1 );
                

                我已经尝试使用语法来尝试并明确地解决我想要的代码中的哪个函数,到目前为止,如果没有运气就无法工作.如何编写绑定行以选择采用两个整数参数的调用?

                I have tried playing around with the syntax to try and explicitly resolve which function I want in the code that does not work without luck so far. How do I write the bind line in order to choose the call that takes the two integer arguments?

                推荐答案

                你需要一个强制转换来消除重载函数的歧义:

                You need a cast to disambiguate the overloaded function:

                (int(A::*)(int,int))&A::operator()
                

                这篇关于std::bind 重载解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 C++ 中进行柯里化? 下一篇:声明 C++ 不可变类的惯用方法

                相关文章

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

                    <small id='9b8jt'></small><noframes id='9b8jt'>

                    <tfoot id='9b8jt'></tfoot>
                    <legend id='9b8jt'><style id='9b8jt'><dir id='9b8jt'><q id='9b8jt'></q></dir></style></legend>