【发布时间】:2019-08-05 00:55:31
【问题描述】:
我正在尝试将函数作为参数传递给类,但出现use of class template requires template argument list 错误。
#include <iostream>
void f_global ()
{
std::cout << "In function global\n";
}
template<typename F>
class A
{
public:
F f1;
A(const int var1, F fun1) : a(var1), f1(fun1) {}
void f2();
private:
int a;
};
void A::f2()
{
std::cout << "in A::f2()\n";
}
int main()
{
A obj(5,f_global);
obj.f2();
}
我在从obj What are template deduction guides and when should we use them? 传递函数时尝试使用自动模板推导功能
【问题讨论】:
-
哪一行触发了错误?您使用的是哪个编译器、版本和标志?