栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++ 多线程unique

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++ 多线程unique

#include
#include
#include
#include
using namespace std;
class MyClass
{
public:
	MyClass() { cout << "构造函数" << endl; };
	MyClass(const MyClass& m) { cout << "拷贝构造函数" << endl; };
	~MyClass() { cout << "析构函数" << endl; };
	void fun() {
		cout << "某种行为" << endl;
	}
private:

};

值拷贝
//void func_value(int a, MyClass mm) {
//	cout << "值传递" << endl;
//	return;
//}
指针传递
//void func_p(int* a, MyClass* mm) {
//	cout << "指针传递" << endl;
//	return;
//}
//引用传递
//void func_ref(int& a, MyClass& mm) {
//	cout << "引用传递" << endl;
//	return;
//}
//unique_ptr
//void func_uniqueptr(int& a, unique_ptr mm) {
//	cout << "func_uniqueptr" << endl;
//	return;
//}
void func_sharedptr(int& a, shared_ptr mm) {
	cout << "func_sharedptr" << endl;
	return;
}
int main() {
	int aa = 10;
	//MyClass my;
	//unique_ptr my(new MyClass);

	
	//thread task2(func_p, &aa, &my);
	task2.join();
	//task2.detach();
	
	shared_ptr my(new MyClass);
	thread task4(func_sharedptr, ref(aa), ref(my));
	task4.detach();
	my->fun();
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1038440.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号