Win32 CreateThread传递参数,值发生改变
庆IT 2013-12-30 10:39:09 #include "stdafx.h"
#include <vector>
#include <winbase.h>
using namespace std;
template<class _TA>
class CThread
{
public:
static DWORD WINAPI ThreadProc(LPVOID _param)
{
if (_param)
{
CThread* pThis = (CThread*)_param;
if (pThis)
{
if (pThis->m_pOwner)
pThis->m_pOwner->DoThread(pThis->m_pOwner);
}
}
return 0;
}
void StartThread (_TA* pOwner_)
{
this->m_pOwner = pOwner_;
hThread_ = CreateThread(0, 0, ThreadProc, (LPVOID)this, 0, 0);
}
protected:
_TA* m_pOwner;
HANDLE hThread_;
};
class A
{
protected:
CThread<A> thread_;
friend class CThread<A>;
public:
void DoThread(void* pParam)
{
int a2 = a1;
int b2 = b1;
vector<char> vecChar2 = vecChar;
Fun();
}
void Fun(){}
void Start(int a,int b,vector<char> vec)
{
a1 = a;
b1 = b;
vecChar = vec;
thread_.StartThread(this);
}
public:
int a1;
vector<char> vecChar;
int b1;
};
int main()
{
A a;
vector<char> vChar;
vChar.push_back(100);
a.Start(3,4,vChar);
return 1;
}
各位大虾们帮忙看看:为什么调用到DoThread,对象A中的成员a1,b1,vecChar变量的值会变换,不是原来的值?编译器为VS2005。谢谢,急。。。