简体   繁体   中英

Assigning a bound function to a std::function

This wont compile for me:

int i = 1;
std::function<void(std::vector<int>&)> execute = std::bind(append<int>, _1, std::ref(i));

Where append has the signature:

template<class T>
void append(std::vector<T>& container, const T& valueToAppend)

Is it obvious as to what I'm doing wrong?

The comiler error is:

error C2664: 'void (std::vector<_Ty> &,const T &)' : cannot convert parameter 1 from 'boost::arg<I>' to 'std::vector<_Ty> &'
1>          with
1>          [
1>              _Ty=int,
1>              T=int
1>          ]
1>          and
1>          [
1>              I=1
1>          ]
1>          and
1>          [
1>              _Ty=int
1>          ]

你需要

using namespace std::placeholders;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM