您的位置:首页 > 其它

MFC重写CView的getDocument()函数没有实现多态,只是静态联编

2012-10-13 19:44 661 查看
class CsniffDoc : public CDocument

{

public:

void CapturePachet();

}

class majorView : public CFormView

{

public:

CsniffDoc* GetDocument() const;

}

CDocument* currentDoc=GetActiveView()->GetDocument();

currentDoc->capturePachet();//

系统总是提示capturepachet()不是CDocument的成员函数,后来将加红的两条语句改成如下:

CsniffDoc* currentDoc=(CsniffDoc*)GetActiveView()->GetDocument());

currentDoc->CapturePachet();

这样就可以啦。

为什么等号后面加个强制指针类型转换?我查看了一下CFormview及其基类CView,发现getDocument()函数并没定义为virtual。也就是说这里边并没有用到多态的知识,只是静态联编而已。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐