我在一个文件内定义了一个静态成员变量,(我在定义该类的.cpp文件中初始化了)然后我想在另外一个文件里用,下面这是部分代码,我引用到的这个静态成员变量依然为0,这是怎么回事?谢谢回答,
// 调用挂断事件按钮,获取当前时间,写入日志文件,
CString time = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
vTelEndTime=CTime::GetCurrentTime();
CTimeSpan cts;
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CMyFormView *pView = (CMyFormView *) pChild->GetActiveView();
CPropPage1 * cp1;
cp1 = (CPropPage1 *)pView->m_PropSheet.GetActivePage(); CTime telStartTime=CPropPage1::vTelStartTime;
cts=vTelEndTime-telStartTime;
CString timelen=cts.Format("%H:%M:%S");
CString weijie;
weijie="视频去电";
CPropPage4* cp4;
(CPropPage4 *)pView->m_PropSheet.GetActivePage();
cp4->TelHistory0(time,timelen,m_tel,weijie);
vTelStartTime就是这个变量
// 调用挂断事件按钮,获取当前时间,写入日志文件,
CString time = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
vTelEndTime=CTime::GetCurrentTime();
CTimeSpan cts;
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CMyFormView *pView = (CMyFormView *) pChild->GetActiveView();
CPropPage1 * cp1;
cp1 = (CPropPage1 *)pView->m_PropSheet.GetActivePage(); CTime telStartTime=CPropPage1::vTelStartTime;
cts=vTelEndTime-telStartTime;
CString timelen=cts.Format("%H:%M:%S");
CString weijie;
weijie="视频去电";
CPropPage4* cp4;
(CPropPage4 *)pView->m_PropSheet.GetActivePage();
cp4->TelHistory0(time,timelen,m_tel,weijie);
vTelStartTime就是这个变量
应该是个全局变量,不知你为什么定义为静态变量。
cp1 = (CPropPage1 *)pView->m_PropSheet.GetActivePage(); CTime telStartTime=CPropPage1::vTelStartTime;
==
你都已经得到cp1了。
首先看一下cp1,其中的vTelStartTime是多少。
其次,CTime telStartTime = cp1.vTelStartTime看看。