在线帮助手册 https://zh.cppreference.com/w/cpp
智能指针
share_ptr 、weak_ptr、unique_ptr
share_ptr 掌控声明周期,和引用计数
weak_ptr 如果有对象有引用计数则可管理,没有就算了。
他们适用的场合也不同,第二种适用于例如系统提供的对象,或者第三方提供的,我要用但是我不能完全的掌控他的关闭可开启;
std::function
std:bind
#include <iostream>
#include <thread>
#include <mutex>
class A{
public:
A() { }
~A() {}
int x;
};
void threadPor(A a)
{
std::cout << a.x << std::endl;
}
int main()
{
A a;
a.x = 1;
auto th = new std::thread(std::bind(&threadPor,a),1);
th->join();
delete th;
system("pause");
return 0;
}
bind 一些注意事项:
A 类中如果有堆区数据,要 ----深拷贝。