下面这段程序有编译错误。
我想在 OnOldProcess() 中 通过函数指针调用成员函数 OldRecordsProcess(). 但编译不能通过
同一函数如果是全局函数,就能编译。请问高手,错在什么地方,怎么修改?
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;
class SiteStates
{
};
typedef int (* _PFUNC)(ifstream *ifp, SiteStates **psiteOldStates);
class CPollerAlertApp
{
private:
ifstream ifp;
SiteStates **psiteOldStates; // record previous data records for each sites
public:
CPollerAlertApp(){};
void OnOldProcess();
private:
/*********************************************/
/* functions */
/*********************************************/
/*************** PollerAlert.c ********************/
void RunDataProcess(_PFUNC pfunc);
protected:
int OldRecordsProcess(ifstream *ifp, SiteStates **psiteOldStates);
};
int OldRecordsProcess(ifstream *ifp, SiteStates **psiteOldStates)
{
return(0);
}
/////////////////////////////////////////////////////////////////////////////
// CPollerAlertApp message handlers
void CPollerAlertApp::OnOldProcess()
{
// TODO: Add your command handler code here
RunDataProcess:OldRecordsProcess);
RunDataProcess(OldRecordsProcess); /* compiler error here */
}
void CPollerAlertApp::RunDataProcess(_PFUNC pFunc)
{
pFunc(&ifp, psiteOldStates);
}
void main()
{
CPollerAlertApp *pApp = new CPollerAlertApp;
pApp->OnOldProcess();
}
我想在 OnOldProcess() 中 通过函数指针调用成员函数 OldRecordsProcess(). 但编译不能通过
同一函数如果是全局函数,就能编译。请问高手,错在什么地方,怎么修改?
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;
class SiteStates
{
};
typedef int (* _PFUNC)(ifstream *ifp, SiteStates **psiteOldStates);
class CPollerAlertApp
{
private:
ifstream ifp;
SiteStates **psiteOldStates; // record previous data records for each sites
public:
CPollerAlertApp(){};
void OnOldProcess();
private:
/*********************************************/
/* functions */
/*********************************************/
/*************** PollerAlert.c ********************/
void RunDataProcess(_PFUNC pfunc);
protected:
int OldRecordsProcess(ifstream *ifp, SiteStates **psiteOldStates);
};
int OldRecordsProcess(ifstream *ifp, SiteStates **psiteOldStates)
{
return(0);
}
/////////////////////////////////////////////////////////////////////////////
// CPollerAlertApp message handlers
void CPollerAlertApp::OnOldProcess()
{
// TODO: Add your command handler code here
RunDataProcess:OldRecordsProcess);
RunDataProcess(OldRecordsProcess); /* compiler error here */
}
void CPollerAlertApp::RunDataProcess(_PFUNC pFunc)
{
pFunc(&ifp, psiteOldStates);
}
void main()
{
CPollerAlertApp *pApp = new CPollerAlertApp;
pApp->OnOldProcess();
}