static _SUB_THREAD* SubThread() 

static _SUB_THREAD* SubThread = new _SUB_THREAD();  
if(!SubThread) 

SubThread = NULL;

return SubThread; 

解决方案 »

  1.   

    这样就更不对了,我已经解决了,但不知道为什么会这样。
    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就可以了。
      

  2.   

    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; 
    } 反正你会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;  
      }  
    };  至于这样用为什么是正确的可能是你把它作为成员函数的话,构造函数反正只调用一次,而且是全局的
    那么地址在子线程和主线程调用的是同一个对象,内存的话也就不变拉 
    不晓得对不对 ??
      

  3.   

    答7楼:我这样做是为了,以后能在进程间使用这个结构的方便。
    另外,static _SUB_THREAD* SubThread()   
      {   
        static _SUB_THREAD* SubThread = NULL;   
        if(!SubThread)   
        {   
          SubThread = new _SUB_THREAD();   
        }   
        return SubThread;   
      }  
    它作为一个静态的公有函数也不会被多次执行吧?
      

  4.   

    static _SUB_THREAD* SubThread = NULL; 
    为什么不在外部定义?
      

  5.   

    struct _SUB_THREAD 

    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;