static _SUB_THREAD* SubThread()
{
static _SUB_THREAD* SubThread = new _SUB_THREAD();
if(!SubThread)
{
SubThread = NULL;
}
return SubThread;
}
{
static _SUB_THREAD* SubThread = new _SUB_THREAD();
if(!SubThread)
{
SubThread = NULL;
}
return SubThread;
}
struct _SUB_THREAD
{
BOOL m_IsDownLoad;
BOOL m_bRequestData;
CString m_strBaseUrl;
static _SUB_THREAD* SubThread()
{
static _SUB_THREAD* SubThread = NULL;
if(!SubThread)
{
SubThread = new _SUB_THREAD();
}
return SubThread;
}
}; #define m_subThread _SUB_THREAD::SubThread()
这样,用m_subThread就可以了。
{
BOOL m_IsDownLoad;
BOOL m_bRequestData;
CString m_strBaseUrl;
};
static _SUB_THREAD* SubThread()
{
/* static */ _SUB_THREAD* SubThread = NULL;
if(!SubThread)
{
SubThread = new _SUB_THREAD();
}
return SubThread;
} 反正你会new 一个 干吗还要把它设为static呢
struct _SUB_THREAD
{
BOOL m_IsDownLoad;
BOOL m_bRequestData;
CString m_strBaseUrl;
static _SUB_THREAD* SubThread()
{
static _SUB_THREAD* SubThread = NULL;
if(!SubThread)
{
SubThread = new _SUB_THREAD();
}
return SubThread;
}
}; 至于这样用为什么是正确的可能是你把它作为成员函数的话,构造函数反正只调用一次,而且是全局的
那么地址在子线程和主线程调用的是同一个对象,内存的话也就不变拉
不晓得对不对 ??
另外,static _SUB_THREAD* SubThread()
{
static _SUB_THREAD* SubThread = NULL;
if(!SubThread)
{
SubThread = new _SUB_THREAD();
}
return SubThread;
}
它作为一个静态的公有函数也不会被多次执行吧?
为什么不在外部定义?
{
BOOL m_IsDownLoad;
BOOL m_bRequestData;
CString m_strBaseUrl;
};_SUB_THREAD* SubThread = NULL; //放在函数外面, 用global空间
static _SUB_THREAD* SubThread()
{
//static _SUB_THREAD* SubThread = NULL;
if(!SubThread)
{
SubThread = new _SUB_THREAD();
}
return SubThread;
}