#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; }



