std::vector<int> v1;
std::function<void(const int&)> funct =
static_cast<std::function<void(const int&)>>(std::bind(
&std::vector<int>::push_back,
&v1,
std::placeholders::_1));
這給我no matching function for call to bind
。std :: bind未按預期工作
我能夠做到這一點,雖然:
threadPool.push_back(std::thread(runThread<lazyFunct>,
std::bind(&LazySkipList<int>::add,
&lsl, std::placeholders::_1), 0, 1000000, 1000000));
我使用的Xcode 4.4 LLVM C++ 11的支持。
你可能會更好過更換'的std ::功能<無效(const int的&)>本功能= 的static_cast <使用'auto funct = std :: bind(...)'調用std :: function>(std :: bind(...))'。更可讀的imo。 –
chris
自動本功能=標準::綁定(&的std ::矢量 ::的push_back,&V1,性病::佔位符:: _ 1);給我同樣的錯誤...我接受可讀性方面... –
是的,C++ 11中的所有'auto'都是基於初始化的類型推斷出的類型。 'auto var = 5;'將產生'var'作爲'int'。有些特定的情況,例如'std :: bind'和迭代器聲明,這些功能在我的書中非常有用。 – chris