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。也就是说这里边并没有用到多态的知识,只是静态联编而已。