首先我在VC工程中添加一个CPublic类:.h文件如下:
class CPublic  
{
public:
CPublic();
virtual ~CPublic();public:
static int m_sIsLogin;
};
在.cpp文件中,类的外面进行初始化:int CPublic::m_sIsLogin = 1;在工程的其他类中:CLOGIN_DLG.cpp中一个函数如下操作:
void CLOGIN_DLG::OnCancelBtn() 
{
CPublic::m_sIsLogin = 0;
OnCancel();
}//其实就是一个登录对话框,当点击取消按钮的时候将CPublic::m_sIsLogin值置为 0;现在问题是程序编译通过,当在登录对话框点击取消按钮时,就是执行上面的取消函数时报错,弹出窗口说内存不能为读。
请各位大侠帮忙!

解决方案 »

  1.   

    已经初始化了啊,
    在.cpp文件中,类的外面进行初始化:int CPublic::m_sIsLogin = 1;
      

  2.   

    你没有实例化,这样的话,cpp中内容并没有执行,所以,要在一个肯定执行的地方初始化一次
      

  3.   

    debug调试跟踪,感觉你的问题没有真正描述出来。
      

  4.   

    m_sIsLogin 这个弄成静态的做什么直接做个标志位什么的不是更好吗?
    感觉这里静态没用。
      

  5.   

    错了把CPublic类的头文件加进去就OK了
      

  6.   

    you must define a object to call this global variable.If you can't do this,the complier can't check anything object for class,as all of you knows,although this variable belongs to local class,you must have a tool to act it before you prepare to use variable.