帮忙看下我在一个类里面定义了共有成员想在另一个类里面去获得这个类的成员的值为什么每次都是空值!void CKeView::OnBtnKselect() 
{
// TODO: Add your control notification handler code here

m_str1=m_pSet->m_column2;//给共有变量赋值。
m_find.Create(IDD_DIALOG4,this);
m_find.ShowWindow(SW_SHOW);
}
void CFind::OnBtnCha() 
{
// TODO: Add your control notification handler code here
CKeView pview;
CString str;
str=pview.m_str1;//想从这里获取为什么不行啊。
MessageBox(str);
m_scan.DoModal();
}

解决方案 »

  1.   

    CKeView pview;
    CString str;
    str=pview.m_str1;//想从这里获取为什么不行啊。
    囧,你重新定义了一个CkeyView的对象,当然里面的成员的值为初始值
      

  2.   

    因为你NEW 出来的那个pview的对象已经不是原来那个了。
    可以这样解决。在 pview 类里面 定义一个全局变量 pview *g_pview  =NULL ;
    初始化完了之后 pview = this 
    然后在你要用的类里面 extern pview *g_pview  ;
      

  3.   


    void CFind::OnBtnCha()  
    {
    // TODO: Add your control notification handler code here
    CKeView* pView = (CKeView*)GetParent();
    ASSERT(pView);
    CString str;
    str=pView->m_str1;
    MessageBox(str);
    m_scan.DoModal();
    }
      

  4.   

    extern pview *g_pview 这句编译说通不过。。