有一C++类Myclass
{
  BOOL A;   //一bool型变量
  fun();
};
然后在Myclass的一个函数fun里创建线程AThread
Myclass::fun()

   A = true;//已赋值为true
   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)AThread, this, NULL, NULL);//this传给线程函数
}
//在AThread线程里创建了BThread
UINT AThread(void* P)
{
   CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)BThread, (Myclass*)p, NULL, NULL);//p传给线程函数
}
UINT BThread(void* p)
{
  Myclass* ptr = (Myclass*)p;
  if(ptr->A == true)
 {
    //dosomething//无法进入此if!!!!!!!!!!
  }
}
调试状态下,我把鼠标指向ptr->A,可看到为true,可是就是if(ptr->A == true)不成立!!!!
if(ptr->A)
{
  //dosomething这样就可以!
}
求解释....

解决方案 »

  1.   

    你保证Myclass对象的生命周期了么
      

  2.   

    注意BOOL 和 bool有区别的
      

  3.   

    #include "stdafx.h"#include <Windows.h>
    class MyClass;
    DWORD WINAPI AThread(void* P);class MyClass
    {
    public:
    bool A;
    void fun()
    {
    A = true;
    CreateThread(NULL, 0, AThread, this, NULL, NULL);
    }
    };DWORD WINAPI BThread(void* p)
    {
    MyClass* ptr = (MyClass*)p;
    if(ptr->A == true)
    {
    MessageBox(NULL, _T("IN"), NULL, 0);
    }
    return 0;
    }DWORD WINAPI AThread(void* p)
    {
    CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)BThread, (MyClass*)p, NULL, NULL);//p传给线程函数
    return 0;
    }int _tmain(int argc, _TCHAR* argv[])
    {
    MyClass a;
    a.fun();
    Sleep(10000);
    return 0;
    }
    测试没问题~
      

  4.   

    我的程序中是小写的bool....,但是还是不解啊
      

  5.   

    有请:百度百科http://baike.baidu.com/view/1557195.htm#1
      

  6.   

    里面有句话,不是很理解。
    3、取值不同
      bool取值false和true,是0和1的区别; false可以代表0,但true有很多种,并非只有1。
    “但true有很多种,并非只有1。” 那除了1,还有什么呢?