c++11特性之std::thread--初识二

来源:互联网 发布:电信4g卡显示3g网络 编辑:程序博客网 时间:2024/04/28 17:43

上篇博客《c++11特性之std::thread–初识》初步介绍了std::thread,并且介绍了几个成员函数。

最后的一段代码留了点悬念,就是vs2015会报错,错误如下:

 error C2893: 未能使函数模板“unknown-type std::invoke(_Callable &&,_Types &&...)”专用化1>  d:\program files (x86)\microsoft visual studio 14.0\vc\include\thr\xthread(238): note: 用下列模板参数:...========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

代码改为:

#include <iostream>#include <thread>using namespace std;class Foo{    void bar_i() { cout << "hello" << endl; }public:    void bar()    {        auto func = std::bind(&Foo::bar_i, this);        std::thread t(&Foo::bar_i, this);        t.join();    }};int main(){    Foo f;    f.bar();}

至于原因呢?
在std::thread中,指向成员函数的指针知道第一个参数是引用。

哈哈 上面一句话太牵强了,好吧 我也不是真正的理解

请大神指点迷津、

0 0