声明*C某类::Getdocument();(已声明,不兼容)

C语言 码拜 8年前 (2016-04-27) 2028次浏览
创建了一个CRightWindow类,基类为CScrollView,在.h文件中如下:
public:
CMy2015Doc* GetDocument();           // error C2143: 语法错误 : 缺少“;”(在“*”的前面)
// error C4430: 缺少类型说明符 – 假定为 int。注意: C++ 不支持默认 int
在.cpp文件中如下:
CMy2015Doc* CRightWindow::GetDocument()         //error C2556: “CMy2015Doc *CRightWindow::GetDocument(void)”:
//重载函数与“int *CRightWindow::GetDocument(void)”只是在返回类型上不同
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy2015Doc)));
return (CMy2015Doc*)m_pDocument;
}
其他的诸如OnDraw,OnInitialUpdate中均有:
CMy2015Doc* pDoc = GetDocument();           // error C2440: “初始化”: 无法从“int *”转换为“CMy2015Doc *”
提示错误如上。
问一下应该怎么改?
解决方案

10

使用强制类型转换?

20

只有返回值类型不同不能构成重载

20

加个前置声明
class CMy2015Doc;
然后在 实现文件中
#include “My2015Doc.h”

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明声明*C某类::Getdocument();(已声明,不兼容)
喜欢 (0)
[1034331897@qq.com]
分享 (0)