/*
* GridTest.h
*
* Created on: 2009-2-27
* Author: Administrator
*/
#ifndef GRIDTEST_H_
#define GRIDTEST_H_
class GridTest {
static const int x=3,y=4;
public:
GridTest();
virtual ~GridTest();
typedef int (GridTest:: *memberFuncType)(int x, int y);
void display();
int foreach(memberFuncType fn, int i, int j);
int test1(int x, int y);
int test2(int x, int y);
int test3(int x, int y);
int test4(int x, int y);
};
#endif /* GRIDTEST_H_ */
/*
* GridTest.cpp
*
* Created on: 2009-2-27
* Author: Administrator
*/
#include "GridTest.h"
#include <iostream>
using namespace std;
GridTest::GridTest() {
// TODO Auto-generated constructor stub
}
GridTest::~GridTest() {
// TODO Auto-generated destructor stub
}
int GridTest::foreach(memberFuncType fn, int x, int y){
cout<<"GridTest::foreach(memberFuncType fn, int x, int y)執行了"<<endl;
cout<<"fn(x,y)"<<(this->*fn)(x, y);
return (this->*fn)(x, y);
}
int GridTest::test1(int x, int y){
cout<<"GridTest::test1(int x, int y)執行了!"<<endl;
return 0;
}
int GridTest::test2(int x, int y){
cout<<"GridTest::test2(int x, int y)執行了!"<<endl;
return 0;
}
int GridTest::test3(int x, int y){
cout<<"GridTest::test3(int x, int y)執行了!"<<endl;
return 0;
}
int GridTest::test4(int x, int y){
cout<<"GridTest::test4(int x, int y)執行了!"<<endl;
return 0;
}
void GridTest::display(){
cout << this->foreach( this->test1, 4, 5);
//一直報錯:no matching function for call to `GridTest::foreach(<unknown type>, int, int)'
}
int main()
{
GridTest *grid;
grid= new GridTest();
grid->display();
return 0;
}
這段代碼在VC6.0上就沒有問題,在Eclipse上編譯就報錯
no matching function for call to `GridTest::foreach(<unknown type>, int, int)'
}
posted on 2009-03-09 17:14
華劍緣 閱讀(1592)
評論(5) 編輯 收藏 引用