Obtendo erro de 'identificador não declarado'
-
26-09-2019 - |
Pergunta
Seguindo o tutorial em http://www.codersource.net/mfc/mfc-tutorials/ctabctrl.aspx , Eu declarei a função ActivateTabDialogs()
no meu arquivo de cabeçalho e chamou -o dentro de outra função na minha classe. O compilador dá erro C2065: 'ActivateTabDialogs' : undeclared identifier
, na linha ActivateTabDialogs();
dentro da definição da função OnSelChange()
. O que estou violando aqui?
Aqui está minha parte da declaração no arquivo de cabeçalho 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();
Aqui está a definição de ActivateTabDialogs()
E a parte que estou chamando de dentro 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;
}
Obrigado.
Solução 3
Acontece que eu não adicionei o manipulador usando o assistente de classe e coloquei a função OnSelChange()
manualmente, e isso estava causando o problema. Muito obrigado pela sua atenção
Outras dicas
Bem aparentemente OnSelChange
é uma função livre. ActiveTabDialogs
é uma função de membro da classe CTCGeriArama_TabCtrl
. As funções do membro devem ser chamadas em uma instância da classe das quais são membros. Existem duas opções:
- Faço
OnSelChange
uma função de membro deCTCGeriArama_TabCtrl
também. - Mudar a chamada para
someObj.ActiveTabDialogs()
e fornecerOnSelChange
com uma referência a umCTCGeriArama_TabCtrl
-instância.
Pela aparência disso OnSelChange
é uma função de retorno de chamada. Provavelmente seria difícil torná-lo uma função de membro, pois isso mudaria seu tipo de ponteiro. Se este é um retorno de chamada para alguma estrutura que você está usando, você deve verificar se essa estrutura fornece algum mecanismo para passar a informação de contexto para o manipulador de retorno (provavelmente o que o NMHDR* pNMHDR
-Parâmetro é para).
No link dado por você a função OnSelchange
é uma função de membro.
Portanto, tente mudar
void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
para:
void CTCGeriArama_TabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)