主题:绘图函数的错误
这是我照书抄的,王育坚主编的<<Visual C++面向对象程序设计>>,这个程序是用来绘图的,可以保存视图中的线条到文档中。下面是向源文件CMyDrawDoc.cpp中编写的实现代码,是将书上的代码添加到程序中的。
void CMydrawDoc::AddLine(CPoint pt1,CPoint pt2)
{
CLine *pLine=new CLine(pt1,pt2); //新建一条线段对象
m_LineArray.Add(pLine); //将线段对象加入动态
}
CLine *CMydrawDoc::GetLine(int nIndex)
{
if(nIndex<0||nIndex>m_LineArray.GetUpperBound() ) //判断是否越界
return NULL;
return m_LineArray.GetAt(nIndex); //返回给定序号线段对象的指针
}
int CMydrawDoc::GetNumLines()
{
return m_LineArray.GetSize(); //返回线段的数量
}
编译运行时出现以下内容:
Compiling...
MydrawDoc.cpp
d:\vc98\mfc\include\afxtempl.h(1539) : error C2664: 'Add' : cannot convert parameter 1 from 'class CLine *' to 'class CObject *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\vc98\mfc\include\afxtempl.h(1539) : while compiling class-template member function 'int __thiscall CTypedPtrArray<class CObArray,class CLine *>::Add(class CLine *)'
执行 cl.exe 时出错.
Mydraw.exe - 1 error(s), 0 warning(s),
我是照书抄的,错在哪里?
void CMydrawDoc::AddLine(CPoint pt1,CPoint pt2)
{
CLine *pLine=new CLine(pt1,pt2); //新建一条线段对象
m_LineArray.Add(pLine); //将线段对象加入动态
}
CLine *CMydrawDoc::GetLine(int nIndex)
{
if(nIndex<0||nIndex>m_LineArray.GetUpperBound() ) //判断是否越界
return NULL;
return m_LineArray.GetAt(nIndex); //返回给定序号线段对象的指针
}
int CMydrawDoc::GetNumLines()
{
return m_LineArray.GetSize(); //返回线段的数量
}
编译运行时出现以下内容:
Compiling...
MydrawDoc.cpp
d:\vc98\mfc\include\afxtempl.h(1539) : error C2664: 'Add' : cannot convert parameter 1 from 'class CLine *' to 'class CObject *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\vc98\mfc\include\afxtempl.h(1539) : while compiling class-template member function 'int __thiscall CTypedPtrArray<class CObArray,class CLine *>::Add(class CLine *)'
执行 cl.exe 时出错.
Mydraw.exe - 1 error(s), 0 warning(s),
我是照书抄的,错在哪里?