不是編譯我試圖編譯從here採取了以下代碼,但我得到一個編譯錯誤。有沒有人有任何想法可能是錯誤的?的std ::功能在VS2012
代碼
#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);
}
編譯錯誤:
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> *'
感謝。
@jogojapan:'print_add'有兩個參數,它有一個_implicit_'this' 'Foo const *'類型的參數也是如此。 –
@ K-ballo對不起。 – jogojapan
@ K-BALLO:如果它的第一個參數類型是(參考/指針)類型的構件的'的std :: function'自動使用'的std :: mem_fn'。 – Xeo