类成员指针 error C2064: term does not evaluate to a function
2009-06-27 23:52
375 查看
定义一个类,类中有几个函数成员完成相似的功能,根据调用者选的模式对相应的函数进行调用 在Funtion()函数下如果按下面的代码调用的话,由于这个Funtion()频繁调用(成千上万次).如果每次都进行判断性能会降低很多.所以准备用类成员函数代替下面的段代码.
switch(iFlag)
{
case 1:
Fun1();
break;
case 2:
Fun2();
break;
case 3:
Fun3();
break;
}
在类中定义
typedef void (BaseClass::*FUN)();
然后声明函数成员
FUN m_fun;
在构造函数中根据相应的模式进行指针赋值
switch(iFlag)
{
case 1:
m_fun=Fun1;
break;
case 2:
m_fun=Fun2;
break;
case 3:
m_fun=Fun3;
break;
}
在调用出直接用类成员函数指针调用.却报了error C2064: term does not evaluate to a function这个错误
Funtion()
{
m_fun();
}
呵呵..其实原因很简单..成员函数指针和类成员函数指针的区别就是累成员函数会有一个this指针需要 加上这个指针上述代码改为下面的形式..ok.编译成功.....
Funtion()
{
(this->*m_fun)();
}
switch(iFlag)
{
case 1:
Fun1();
break;
case 2:
Fun2();
break;
case 3:
Fun3();
break;
}
在类中定义
typedef void (BaseClass::*FUN)();
然后声明函数成员
FUN m_fun;
在构造函数中根据相应的模式进行指针赋值
switch(iFlag)
{
case 1:
m_fun=Fun1;
break;
case 2:
m_fun=Fun2;
break;
case 3:
m_fun=Fun3;
break;
}
在调用出直接用类成员函数指针调用.却报了error C2064: term does not evaluate to a function这个错误
Funtion()
{
m_fun();
}
呵呵..其实原因很简单..成员函数指针和类成员函数指针的区别就是累成员函数会有一个this指针需要 加上这个指针上述代码改为下面的形式..ok.编译成功.....
Funtion()
{
(this->*m_fun)();
}
相关文章推荐
- 类成员指针 error C2064: term does not evaluate to a function
- error C2064: term does not evaluate to a function惯性思维:乘号写掉了的坏习惯
- VC6.0: error C2064: term does not evaluate to a function
- VC中出现error C2064: term does not evaluate to a function
- error C2064: term does not evaluate to a function
- c++ error 2064: term does not evaluate to a function taking 1 arguments解决方法
- C2064: term does not evaluate to a function解决方法
- .size expression for apf_page_fault does not evaluate to a constant
- Pointers to Class Members Are Not Pointers(指向类成员函数的“指针”并非指针)
- freemarker 异常 student.age does not evaluate to true/false
- size expression for do_hypervisor_callback does not evaluate to a constant
- size expression for do_hypervisor_callback does not evaluate to a constant
- cannot add a child that doesnot have a YogoNode to a parent without a measure function!
- C++ 成员函数指针的问题 pointer-to-member-function
- 2017.7.10 Package name does not correspond to the file path
- centos系统 解决Device eth0 does not seem to be present
- JSP中出现According to TLD or attribute directive in tag file, attribute value does not accept any expressions
- centos网卡错误Device eth0 does not seem to be present
- repo sync出现“fatal: '../platform/abi/cpp.git' does not appear to be a git repository”的解决方案
- Device eth0 does not seem to be present, delaying initialization