mfc初学

来源:互联网 发布:手机淘宝不弹出淘口令 编辑:程序博客网 时间:2024/05/30 02:25

今天调试了个简单的划线程序,单文档应用程序,包括文档的读写

程序是书上的,应该没有错,可是在运行OnLButtonUp的时候出现了问题,

if (m_ptStart!=m_ptEnd)
 {
  Cline* pLine= new Cline(m_ptStart,m_ptEnd);
  CMyDrawLineDoc* pDoc = GetDocument();
  CObList* pList  =  pDoc->GetLineList();
  pList->AddTail(pLine);
  pDoc->UpdateAllViews(this,NULL,NULL);
  pDoc->SetModifiedFlag(TRUE);
 }

无法从“CObject *”转换为“CObList *”

可能现在的vs2010的规则有些变化,所以我尝试着加了个强制转换,呵呵,结果成功了,Ye!

if (m_ptStart!=m_ptEnd)
 {
  Cline* pLine= new Cline(m_ptStart,m_ptEnd);
  CMyDrawLineDoc* pDoc = GetDocument();
  CObList* pList = NULL;
  pList =(CObList*) pDoc->GetLineList();
  pList->AddTail(pLine);
  pDoc->UpdateAllViews(this,NULL,NULL);
  pDoc->SetModifiedFlag(TRUE);
 }

大胆尝试,才有创新和进步!