【发布时间】:2021-07-28 08:01:40
【问题描述】:
拿这个简单的代码:
void CRestoreSettingsDlg::OnSize(UINT nType, int cx, int cy)
{
CResizingDialog::OnSize(nType, cx, cy);
m_gridBackupLog.ExpandLastColumn();
}
为什么会被标记?
C26434 函数
'CRestoreSettingsDlg::OnSize'隐藏了一个非虚函数'CRestoreDialogDlg::OnSize'。
如你所见,我调用了基类方法。
声明和定义
-
CRestoreSettingsDlg:
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
void CRestoreSettingsDlg::OnSize(UINT nType, int cx, int cy)
{
CResizingDialog::OnSize(nType, cx, cy);
m_gridBackupLog.ExpandLastColumn();
}
-
CResizingDialog:
public:
afx_msg void OnSize(UINT nType, int cx, int cy);
void CResizingDialog::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
Invalidate(TRUE);
}
- 样板基类 (
afxwin.h) 似乎具有:
protected:
afx_msg void OnSize(UINT nType, int cx, int cy);
_AFXWIN_INLINE void CWnd::OnSize(UINT, int, int)
{ Default(); }
继承
class CRestoreSettingsDlg : public CResizingDialogclass CResizingDialog : public CDialogEx
【问题讨论】:
-
问题实际上可能是为什么您不经常看到“错误消息”?例如,我假设您的
CResizingDialog::OnSize()函数也“隐藏”了基类函数(大概是CWnd::OnSize())。这将适用于非虚拟函数(具有afx_msg属性,通常定义为空的函数)的许多 MFC 消息处理程序“覆盖”。 -
也许向我们展示各种
OnSize()成员函数的确切定义/声明,看看它们的签名是否存在奇怪但微妙的差异。 -
这个链接可能很有趣:docs.microsoft.com/en-us/cpp/code-quality/c26434。还向我们展示了在 .h 文件中出现的
CResizingDialog::OnSize和CRestoreSettingsDlg::OnSize的确切声明。 -
@AdrianMole 问题已更新。
-
@Jabberwocky,请参阅docs.microsoft.com/en-us/cpp/code-quality/… 以启用这些警告
标签: visual-c++ mfc code-inspection