gpt4 book ai didi

c++ - 收到 'undeclared identifier' 错误

转载 作者:行者123 更新时间:2023-11-28 01:09:48 26 4
gpt4 key购买 nike

按照 http://www.codersource.net/mfc/mfc-tutorials/ctabctrl.aspx 上的教程进行操作,我在我的头文件中声明了函数 ActivateTabDialogs() 并在我的类中的另一个函数中调用它。编译器在函数 OnSelChange() 定义内的 ActivateTabDialogs(); 行给出错误 C2065: 'ActivateTabDialogs' : undeclared identifier .我在这里违反了什么?

这是我在头文件TCGeriArama_TabCtrl.h中的声明部分

class CTCGeriArama_TabCtrl : public CTabCtrl
{
// Construction
public:
CTCGeriArama_TabCtrl();

// Attributes

//Array to hold the list of dialog boxes/tab pages for CTabCtrl
int m_DialogID[2];

int m_nPageCount;

//CDialog Array Variable to hold the dialogs
CDialog *m_Dialog[2];

public:
// Operations
//Function to Create the dialog boxes during startup
void InitDialogs();

//Function to activate the tab dialog boxes
void ActivateTabDialogs();

这是 ActivateTabDialogs() 的定义以及我在 TCGeriArama_TabCtrl.cpp 中调用它的部分

void CTCGeriArama_TabCtrl::ActivateTabDialogs()
{
int nSel = GetCurSel();
if(m_Dialog[nSel]->m_hWnd)
m_Dialog[nSel]->ShowWindow(SW_HIDE);

CRect l_rectClient;
CRect l_rectWnd;

GetClientRect(l_rectClient);
AdjustRect(FALSE,l_rectClient);
GetWindowRect(l_rectWnd);
GetParent()->ScreenToClient(l_rectWnd);
l_rectClient.OffsetRect(l_rectWnd.left,l_rectWnd.top);
for(int nCount=0; nCount < m_nPageCount; nCount++){
m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_HIDEWINDOW);
}
m_Dialog[nSel]->SetWindowPos(&wndTop, l_rectClient.left, l_rectClient.top, l_rectClient.Width(), l_rectClient.Height(), SWP_SHOWWINDOW);

m_Dialog[nSel]->ShowWindow(SW_SHOW);

}

//Selection change event for the class derived from CTabCtrl
void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
ActivateTabDialogs(); // HERE'S WHERE THE COMPILER GIVES THE ERROR
*pResult = 0;
}

谢谢。

最佳答案

显然 OnSelChange 是一个免费功能。 ActiveTabDialogs 是类 CTCGeriArama_TabCtrl 的成员函数。必须在它们所属的类的实例上调用成员函数。有两种选择:

  1. 也使OnSelChange成为CTCGeriArama_TabCtrl的成员函数。
  2. 更改对 someObj.ActiveTabDialogs() 的调用,并为 OnSelChange 提供对 CTCGeriArama_TabCtrl 实例的引用。

从外观上看,OnSelChange 是一个回调函数。使它成为成员函数可能很困难,因为这会改变它的指针类型。如果这是您正在使用的某个框架的回调,您应该检查该框架是否提供了一些机制来将上下文信息传递给回调处理程序(可能是 NMHDR* pNMHDR 参数的用途) .

关于c++ - 收到 'undeclared identifier' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4012745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com