rxgmoral 发表于 2006-2-27 13:27

为什么不能继承CView类

<P>为什么不能继承CView类<BR>写了一个CmView类并继承CView类</P>
<P>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;CmView.h&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<BR>#pragma once<BR>class CmView : public CView<BR>{<BR> DECLARE_DYNCREATE(CmView)<BR>protected:<BR> CmView();           <BR> virtual ~CmView();<BR>public:<BR> virtual void OnDraw(CDC* pDC);      <BR>#ifdef _DEBUG<BR> virtual void AssertValid() const;<BR>#ifndef _WIN32_WCE<BR> virtual void Dump(CDumpContext&amp; dc) const;<BR>#endif<BR>#endif<BR>};</P>
<P>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;CmView.Cpp&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<BR>#include "stdafx.h"<BR>#include "CmView.h"<BR>IMPLEMENT_DYNCREATE(CmView, CView)<BR>CmView::CmView()<BR>{}<BR>CmView::~CmView()<BR>{}</P>
<P>void CmView::OnDraw(CDC* pDC)<BR>{<BR> CDocument* pDoc = GetDocument();<BR>}<BR>#ifdef _DEBUG<BR>void CmView::AssertValid() const<BR>{<BR> CView::AssertValid();<BR>}</P>
<P>#ifndef _WIN32_WCE<BR>void CmView::Dump(CDumpContext&amp; dc) const<BR>{<BR> CView::Dump(dc);<BR>}<BR>#endif<BR>#endif //_DEBUG</P>
<P>现写了一个继承CmView类<BR>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;LeftWnd.h&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<BR>#pragma once<BR>#include "CmView.h"<BR>class LeftWnd : public CmView<BR>{<BR> DECLARE_DYNCREATE(LeftWnd)<BR>protected:<BR> LeftWnd();          <BR> virtual ~LeftWnd();<BR>public:<BR> virtual void OnDraw(CDC* pDC);      <BR>#ifdef _DEBUG<BR> virtual void AssertValid() const;<BR>#ifndef _WIN32_WCE<BR> virtual void Dump(CDumpContext&amp; dc) const;<BR>#endif<BR>#endif<BR>};</P>
<P>&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;LeftWnd.Cpp&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<BR>#include "stdafx.h"<BR>#include "Test.h"<BR>#include "LeftWnd.h"</P>
<P>IMPLEMENT_DYNCREATE(LeftWnd, CmView)<BR>LeftWnd::LeftWnd()<BR>{<BR>}</P>
<P>LeftWnd::~LeftWnd()<BR>{<BR>}<BR>void LeftWnd::OnDraw(CDC* pDC)<BR>{<BR> CDocument* pDoc = GetDocument();<BR>}<BR>#ifdef _DEBUG<BR>void LeftWnd::AssertValid() const<BR>{<BR> CmView::AssertValid();<BR>}</P>
<P>#ifndef _WIN32_WCE<BR>void LeftWnd::Dump(CDumpContext&amp; dc) const<BR>{<BR> CmView::Dump(dc);<BR>}<BR>#endif<BR>#endif //_DEBUG</P>
<P>编译没有报错,但是运行后报错,错那了</P>
<P>谢谢:)<BR></P>

冰镇柠檬汁儿 发表于 2006-2-28 09:53

CView类是所有视图的基类,怎么会不能继承呢,你报什么错?

页: [1]

编程论坛