/*
* 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
华剑缘 阅读(1577)
评论(5) 编辑 收藏 引用