乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      std::function not compiling in VS2012

       herowuking 2015-11-03

      I am trying to compile the following code taken from here but I am getting a compile error. Does anyone have any ideas what might be wrong?

      The code

      #include <iostream>
      #include <functional>
      
      struct Foo {
          Foo(int num) : num_(num) {}
          void print_add(int i) const { std::cout << num_+i << '\n'; }
          int num_;
      };
      
      
      int main()
      {
          // store a call to a member function
          std::function<void(const Foo&, int)> f_add_display = &Foo::print_add;
          Foo foo(314159);
          f_add_display(foo, 1);
      }

      The compile error :

      Error   1   error C2664: 'std::_Func_class<_Ret,_V0_t,_V1_t>::_Set' : 
      cannot convert parameter 1 from '_Myimpl *' to 'std::_Func_base<_Rx,_V0_t,_V1_t> *' 

      Thanks.


      This looks like a bug in VS2012, I have made a bug report here.For now the following works :Edit: edited based on Xeo's suggestion to use std::mem_fn

      #include <iostream>
      #include <functional>
      
      struct Foo {
          Foo(int num) : num_(num) {}
          void print_add(int i) const { std::cout << num_+i << '\n'; }
          int num_;
      };
      
      int main()
      {
          // store a call to a member function
          std::function<void(const Foo&, int)> f_add_display = std::mem_fn(&Foo::print_add);
          Foo foo(314159);
          f_add_display(foo, 1);
      }
      Your code is kinda strange. You bind foo and still have a std::function<void(const Foo&, int)>. The only reason this works is because std::bind swallows unneeded arguments. The correct equivalent thing to what you're trying in the question would be using std::mem_fn(&Foo::print_add).
                – Xeo  Oct 29
      std::mem_fn is a simple wrapper for member pointers that returns a function object which takes a pointer or reference to the class as its first parameter and every parameter from a member function (if any) after that. std::bind is for binding arguments to a function.
                   – Xeo   Oct 29 '12 at 5:40
        Note that for those who use 2013, I actually able to reproduce the same error even though it has been submitted for 2012. I hope someone else can confirm this too.
                          – Arly   Oct 30 '13 at 12:15                  

        本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
        轉藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多