一个MDI程序
包含一个文档类CMyProj1Doc
和两个视图类 CMyProj1View 以及自己加的 CInputView(继承自CFormView)
在MDIChildWnd中用SplitterWnd切分窗口
问题是:
在CMyProj1View的OnDraw函数内:
CMyProj1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
没有任何问题
而在CInputView内:
CMyProj1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
编译报错error C2440: “初始化”: 无法从“CDocument *”转换为“CMyProj1Doc *”
是什么原因?将两个类对比了一下 发现区别在于一个GetDocument()函数
CMyProj1View中有一个AppWizard自动生成的函数:
CMyProj1Doc* CMyProj1View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyProj1Doc)));
return (CMyProj1Doc*)m_pDocument;
}
而CInputView却没有
是否重写CInputView中的GetDocument()就能解决问题? 为什么?