日本平安京时代:VC主框架类打开文件编程:GETDOCUMENT

来源:百度文库 编辑:高考问答 时间:2024/04/28 10:58:54
void CPictureView::OnFileOpen()
{
// TODO: Add your command handler code here
CPictureDoc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
错误信息:

Compiling...
pictureDoc.cpp
pictureView.cpp
Generating Code...
Skipping... (no relevant changes detected)
picture.cpp
Linking...
pictureDoc.obj : error LNK2001: unresolved external symbol "protected: void __thiscall CPictureDoc::OnFileOpen(void)" (?OnFileOpen@CPictureDoc@@IAEXXZ)
Debug/picture.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

picture.exe - 2 error(s), 0 warning(s)
解决好问题的话,再加10分

你建 消息映射的时候是 选的 文档类!可是你的文件打开的代码写在视图类里的。

解决方法,在 pictureDoc.h 里把 OnFileOpen 的声明删掉。在picturedoc.cpp 里 把消息映射表里的 OnFileOpen 删掉(如果有的话)就行了。

还有楼上说的也是个问题。

CPictureDoc *pDoc=(CPictureDoc *)GetDocument();
GetDocument返回的是Doc类的父类指针,不能直接赋给子类指针,要强制转换。