EOG*_*EOG 1 c++ templates operator-overloading function-call-operator
我试图在c ++中重载函数调用操作符,我得到了这个无法解决的编译错误(Visual Studio 2010).
错误符合要求 act(4);
#include <stdio.h>
#include <iostream>
void Test(int i);
template <class T> class Action
{
private:
void (*action)(T);
public:
Action(void (*action)(T))
{
this->action = action;
}
void Invoke(T arg)
{
this->action(arg);
}
void operator()(T arg)
{
this->action(arg);
}
};
int main()
{
Action<int> *act = new Action<int>(Test);
act->Invoke(5);
act(4); //error C2064: term does not evaluate to a function taking 1 arguments overload
char c;
std::cin >> c;
return 0;
}
void Test(int i)
{
std::cout << i;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
533 次 |
| 最近记录: |