#include <iostream>
#include <memory>
#include <map>
#include <vector>
#include <windows.h>
#include <excpt.h>
#include <process.h>
using namespace std;
class TT
{
public:
TT(){
cout << "TT()" << endl;
}
~TT(){ cout << "~TT()" << endl; }
void myprint(){ cout << "myprint()"<< endl; }
};
struct MyStruct
{
shared_ptr <TT> ptr;
};
class Test
{
public:
Test(){
u_ptr = shared_ptr <TT>(new TT);
cout << "Test()" << endl;
}
~Test(){ cout << "~Test()" << endl; }
static unsigned int __stdcall MyThread(void *p){
cout << "----begin MyThread"<< endl;
MyStruct *tagStr = (MyStruct*)p;
shared_ptr <TT> ptr = tagStr->ptr;
ptr->myprint();
cout << "----ending MyThread" << endl;
Sleep(4000);
cout << "----end MyThread" << endl;
return 0;
}
public:
shared_ptr <TT> u_ptr;
};
int main()
{
cout << "....begin..."<< endl;
{
Test test;
MyStruct s;
s.ptr = test.u_ptr;
UINT HeartThread = ::_beginthreadex(NULL, 0, &Test::MyThread, &s, 0, NULL);
Sleep(1000);
}
cout << "....ending..." << endl;
Sleep(6000);
cout << "....end..." << endl;
system("pause");
return 0;
}
#include <memory>
#include <map>
#include <vector>
#include <windows.h>
#include <excpt.h>
#include <process.h>
using namespace std;
class TT
{
public:
TT(){
cout << "TT()" << endl;
}
~TT(){ cout << "~TT()" << endl; }
void myprint(){ cout << "myprint()"<< endl; }
};
struct MyStruct
{
shared_ptr <TT> ptr;
};
class Test
{
public:
Test(){
u_ptr = shared_ptr <TT>(new TT);
cout << "Test()" << endl;
}
~Test(){ cout << "~Test()" << endl; }
static unsigned int __stdcall MyThread(void *p){
cout << "----begin MyThread"<< endl;
MyStruct *tagStr = (MyStruct*)p;
shared_ptr <TT> ptr = tagStr->ptr;
ptr->myprint();
cout << "----ending MyThread" << endl;
Sleep(4000);
cout << "----end MyThread" << endl;
return 0;
}
public:
shared_ptr <TT> u_ptr;
};
int main()
{
cout << "....begin..."<< endl;
{
Test test;
MyStruct s;
s.ptr = test.u_ptr;
UINT HeartThread = ::_beginthreadex(NULL, 0, &Test::MyThread, &s, 0, NULL);
Sleep(1000);
}
cout << "....ending..." << endl;
Sleep(6000);
cout << "....end..." << endl;
system("pause");
return 0;
}