【发布时间】:2010-04-27 10:11:22
【问题描述】:
我被告知要创建函数模板,它需要 4 个参数:
- 指针
- 参考
- 指向数组的指针
- 函数指针
如何执行此任务?我正在尝试:
#include <iostream>
using namespace std;
int nothing(int a)
{
return a;
}
template<typename T> T func(int *L, int &M, char *K, int (*P)(int))
{
cout << L << "," << M << "," << K[0] << "," << P() << endl;
return 0;
}
int main()
{
int x = 3;
int *z = &x;
int &y = x;
char c[3];
int (*pf)(int) = nothing;
cout << "some result of func" << func(z, y, c, pf) << endl;
system("pause");
return 0;
}
这给了我“没有匹配的功能,我猜是 'pf'。现在我无法控制在 pf 中传递什么或者我错了吗?
【问题讨论】:
-
正如 sbi 指出的那样,不要只是编辑您的问题,使已经给出的答案看起来错误。
标签: c++ templates function-templates