请问:我自己定义了一个类,然后想访问view中的公共成员变量,但访问不了,怎么办? 请问:我自己定义了一个类,然后想访问view中的公共成员变量,但访问不了,怎么办? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的类在那里呀?若是可以, 就放在view 里好了. include类C[XXX]View的头文件。用某种方法得到该view的指针,假如是pView;pView->(public data member). 1、在View的定义上面,宏定义的下面加下 CXXXView *pView;2、在构造函数中pView=this;3、在你要用的类中宏定义的下面extern CXXXView *pView;可以用了:) #include "CMyView.h"#include "MainFrm.h"CMainFrame* pMain = (CMainFrame*) (AfxGetApp()->GetMainWnd());CMyView* pView = (CMyView*) (pMain->GetActiveView());然后就可以通过pView调用当前View的属性成员了。 不好意思,写错了,应该是这样:1、在你的类定义上面,宏定义的下面加下 CXXXView *pView;2、在构造函数中pView=this;3、在View中宏定义的下面extern CXXXView *pView;保证可以,准备给分吧:) #if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000CStyclassView * pView;//连编译都通不过呀。class CMedia {public: CMedia(); virtual ~CMedia();}; 1、确认你的CStyclassView * pView;写在了CXXXView.cpp中2、确认你在构造函数中写了pView=this;例:#include "stdafx.h"#include "MfcFirst.h"#include "MfcFirstDoc.h"#include "MfcFirstView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifCMfcFirstView *pView;CMfcFirstView::CMfcFirstView(){ // TODO: add construction code here pView=this;} 先得到app的指针pApp;然后pApp->GetAfxMainWnd()->GetActiveView() zswzwy(对! 我就是被封杀的☆ZSWZWY☆!) :我在自己定义的类中写:pView->m_iorange=100;但是它还是告诉我pView没有定义。 可能是我还是不明白你的第三步怎么写,再详细点,谢谢。 是这样你一步一步来:1在CXXXView.cpp的宏定义下面加入CXXXView * pView;2在CXXXView.cpp的构造函数中加入pView=this;3在你要使作pView的地方,也就是你的类中(.h或.cpp)的宏定义下面加入extern CXXXView * pView; 如果错误提示CXXXView未定义加入XXXView.hok? 错误提示是这样的:error C2143: syntax error : missing ';'before '*'// Media.cpp: implementation of the CMedia class.////////////////////////////////////////////////////////////////////////#include "styclassview.h"//#include "mainfrm.h"#include "stdafx.h"#include "styclass.h"#include "Media.h"#ifdef _DEBUG#undef THIS_FILEstatic char THIS_FILE[]=__FILE__;#define new DEBUG_NEW#endif//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////extern CStyclassView * pView;CMedia::CMedia(){// CMainFrame* pMain = (CMainFrame*)(AfxGetApp()->GetMainWnd());// CMyView* pView = (CMyView*) (pMain->GetActiveView());//extern CStyclassView * pView;//extern CStyclassView * pView;}CMedia::~CMedia(){}void CMedia::Wavlet(int scalenum, double coef[][220500]){} #include "StyclassView.h"在错误页面的上面 请问你用什么压缩,为什么我连扩展名都看不到呀?你用附件再发一分到我的另一个信箱里:[email protected] 是RAR格式的,你到这下载吧http://count.skycn.com/download.php?id=23&url=http://sdhttp.skycn.net/down/ha_wrar31b4_zmb.exe UpdateData()干啥用? 求教。。。这一句是干什么的 大家好呀,本人想做一个文字识别的软件,但在网上查找了很久都找不到一个词库,谁可为我提供一个,先谢谢了 关于dll引入,高分重赏 100分,(IIS)Web服务器写权限 如何结束由cmd.exe创建的进程 VC抓屏的一个问题 RichEdit控件问题 用VC怎么操作EXCEL文件呀? 二十四点纸牌游戏的原代码,放出来啦!! 关于msdn 一个关于函数指针的问题,请指教
pView->(public data member).
pView=this;3、在你要用的类中宏定义的下面
extern CXXXView *pView;可以用了:)
#include "MainFrm.h"CMainFrame* pMain = (CMainFrame*) (AfxGetApp()->GetMainWnd());
CMyView* pView = (CMyView*) (pMain->GetActiveView());然后就可以通过pView调用当前View的属性成员了。
1、在你的类定义上面,宏定义的下面加下 CXXXView *pView;2、在构造函数中
pView=this;3、在View中宏定义的下面
extern CXXXView *pView;保证可以,准备给分吧:)
#pragma once
#endif // _MSC_VER > 1000CStyclassView * pView;//连编译都通不过呀。class CMedia
{
public:
CMedia();
virtual ~CMedia();
};
2、确认你在构造函数中写了pView=this;例:
#include "stdafx.h"
#include "MfcFirst.h"#include "MfcFirstDoc.h"
#include "MfcFirstView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CMfcFirstView *pView;
CMfcFirstView::CMfcFirstView()
{
// TODO: add construction code here
pView=this;
}
然后pApp->GetAfxMainWnd()->GetActiveView()
但是它还是告诉我pView没有定义。
可能是我还是不明白你的第三步怎么写,再详细点,谢谢。
1在CXXXView.cpp的宏定义下面加入CXXXView * pView;
2在CXXXView.cpp的构造函数中加入pView=this;
3在你要使作pView的地方,也就是你的类中(.h或.cpp)的宏定义下面加入
extern CXXXView * pView; 如果错误提示CXXXView未定义加入XXXView.hok?
// Media.cpp: implementation of the CMedia class.
//
//////////////////////////////////////////////////////////////////////
#include "styclassview.h"
//#include "mainfrm.h"
#include "stdafx.h"
#include "styclass.h"
#include "Media.h"#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
extern CStyclassView * pView;
CMedia::CMedia()
{
// CMainFrame* pMain = (CMainFrame*)(AfxGetApp()->GetMainWnd());
// CMyView* pView = (CMyView*) (pMain->GetActiveView());
//extern CStyclassView * pView;
//extern CStyclassView * pView;}CMedia::~CMedia()
{}void CMedia::Wavlet(int scalenum, double coef[][220500])
{}
在错误页面的上面
你用附件再发一分到我的另一个信箱里:
[email protected]