我用了如下的方法实现。1)包含头文件 #include "MyView.h"
2)在Frame类中,CMyView * m_pView = (CMyView*)this->GetActiveView();
然后访问其中类CMyView中的公共变量就会出错.错误信息如下:
1) myview.h(21) : error C2143: syntax error : missing ';' before '*'
2) myview.h(21) : error C2501: 'CQQDoc' : missing storage-class or type specifiers
3) myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers
2)在Frame类中,CMyView * m_pView = (CMyView*)this->GetActiveView();
然后访问其中类CMyView中的公共变量就会出错.错误信息如下:
1) myview.h(21) : error C2143: syntax error : missing ';' before '*'
2) myview.h(21) : error C2501: 'CQQDoc' : missing storage-class or type specifiers
3) myview.h(21) : error C2501: 'GetDocument' : missing storage-class or type specifiers
class MyView;
把#include "myview.h"去掉
从现象上来看,很可能你的myview.h中需要QQDoc.h头文件。
// Get the active MDI child window.
CMDIChildWnd *pChild =
(CMDIChildWnd *) pFrame->GetActiveFrame();
/* or CMDIChildWnd *pChild =
pFrame->MDIGetActive();
*/
// Get the active view attached to the active MDI child window.
CMyView *pView = (CMyView *) pChild->GetActiveView();
Conquer what is not
如何从Frame类中访问View类中的变量(基于单文档)?
---你们一般是怎么实现的?
任何时候,声明指针的时候都不需要包含定义,使用指针志向的对象的时候才需要包含定义
头文件:
class A;
A* p;
实现文件
#include "a.h"
p->func();