首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

模板与函数指针应用有关问题(测试程序报错),高手,

2012-02-26 
模板与函数指针应用问题(测试程序报错),高手,求救!#includeStdAfx.h #includeiostream.h classA{priva

模板与函数指针应用问题(测试程序报错),高手,求救!
#include   "StdAfx.h "
#include   "iostream.h "

class   A{
private:
int   value;
public:
A(){}
void   setvalue(int   &v){
this-> value=v;
}
void   display(){
cout < < "value= " < <value < <endl;
}
};


template   <   class   T   ,   class   U   >
struct   s{
typedef   T   tTyp;
typedef   void   (T::*memberfxntyp)(U   &);
typedef   void   (T::*dis)();
memberfxntyp   lpMemfn;
dis   lpdis;
};


void   main(){
A   classA;
int   v=5;
classA.setvalue(v);

s <A,int>   s1;
s1.lpdis=A::display;
s1.lpdis();

}
========================================
s1.lpdis();
这句就会报错:
  error   C2064:   term   does   not   evaluate   to   a   function

函数指针在这里应该怎么用啊``谢谢大哥,大姐们!!!

[解决办法]
s <A,int> s1;
s1.lpdis=A::display;
s1.lpdis();
改成这样
s <A,int> s1;
s1.lpdis=&A::display;
(classA.*s1.lpdis)();
你还是看看C++Primer吧
[解决办法]
(classA.*s1.lpdis)();

热点排行