对话框可不可以多重继承。
我的有一个CEasyWorkDlg类。开始是继承自CResizableDlg的。
CResizableDlg是我写的一个类,可以实现对话框中各控件根据对话框大小的自动调整。
后来,我又想在对话框的标题栏加一个类似最大最小化按钮的按钮,用于控制对话框的“总在最前”属性。我想在标题栏画这样一个按钮的工作量很大,于是我又新建了一个类叫CTopableDlg, 想在CTopableDlg里实现这部分工作。代码于是变成下面的样子:
class CResizableDlg : virtual public CDialog
{
...去掉了enum{IDD=...}的定义并且相应修改了构造函数
}
class CTopableDlg : virtual public CDialog
{
...去掉了enum{IDD=...}的定义并且相应修改了构造函数
}
class CEasywordDlg : public CResizableDlg, public CTopableDlg
{
...
}
CEasyWordDlg::CEasyWordDlg(CWnd* pParent /*=NULL*/)
: CResizableDlg(CEasyWordDlg::IDD, pParent),
CTopableDlg(CEasyWordDlg::IDD, pParent)
{
...
}
我就预感编译不过去,果然:
--------------------Configuration: EasyWord - Win32 Debug--------------------
Compiling...
EasyWordDlg.cpp
E:\timepp\program\EasyWord\EasyWordDlg.cpp(132) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(unsigned int,long)' to 'void (__thiscall CWnd::*)(unsigned int,long)'
E:\timepp\program\EasyWord\EasyWordDlg.cpp(132) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(unsigned int,long)' to 'void (__thiscall CWnd::*)(void)'
Pointers to members have different representations; cannot cast between them
E:\timepp\program\EasyWord\EasyWordDlg.cpp(133) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(void)' to 'void (__thiscall CWnd::*)(void)'
E:\timepp\program\EasyWord\EasyWordDlg.cpp(133) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(void)' to 'void (__thiscall CWnd::*)(void)'
E:\timepp\program\EasyWord\EasyWordDlg.cpp(133) : error C2440: 'type cast' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(void)' to 'void (__thiscall CCmdTarget::*)(void)'
E:\timepp\program\EasyWord\EasyWordDlg.cpp(133) : error C2440: 'initializing' : cannot convert from 'void (__thiscall CEasyWordDlg::*)(void)' to 'void (__thiscall CCmdTarget::*)(void)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
....还有好多.......
...................
Generating Code...
Compiling...
EasyWord.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...
EasyWord.exe - 44 error(s), 0 warning(s)
其中在程序中,第132和133行:
130 BEGIN_MESSAGE_MAP(CEasyWordDlg, CResizableDlg)
131 //{{AFX_MSG_MAP(CEasyWordDlg)
132 ON_WM_SYSCOMMAND()
133 ON_WM_PAINT()
134 ON_WM_QUERYDRAGICON()
大侠们救我。是不是和第130行有关,那个CResizableDlg换成CDialog也不行.