上篇博客《[c++11特性之std::thread–初識](http://blog.csdn.net/wangshubo1989/article/details/49592517 "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中,指向成員函數的指針知道第一個參數是引用。
哈哈 上面一句話太牽強了,好吧 我也不是真正的理解
請大神指點迷津、
- 前言
- 吐血整理C++11新特性
- C++11新特性之std::function
- c++11特性之正則表達式
- c++11特性之Lambda表達式
- c++11特性之override和final關鍵字
- c++11特性之std::thread--初識
- c++11特性之std::thread--初識二
- c++11特性之initializer_list
- c++11特性之std::thread--進階
- c++11特性之std::thread--進階二
- C++11新特性之 CALLBACKS
- C++11新特性之 std::array container
- C++11新特性之 nullptr
- C++11新特性之 rvalue Reference(右值引用)
- C++11新特性之 Move semantics(移動語義)
- C++11新特性之 default and delete specifiers
- C++11新特性之 Static assertions 和constructor delegation
- 開始使用C++11的幾個理由
- C++11新特性之 std::future and std::async