函数指针的模板参数推断失败

时间:2016-04-05 15:54:18

标签: c++ templates function-pointers

编译器无法为函数指针扣除模板参数。

bool foo(string a, string b) {
    // SOMETHING
}

功能定义是

foobar f(foo);

我在以下一行遇到麻烦

error: missing template arguments before ‘f’

编译器错误

> df1       
Source      Name                                 Country
 A          Glen fiddich                        United Kingdom
 A          Talisker dark storm                 United Kingdom
 B          johnney walker                      United states
 D          veuve clicquot brut                 France
 E          nicolas feuillatte brut             France
 C          glen morangie                       united kingdom
 B          Talisker 54 degrees                 United kingdom
 F          Talisker dark storm                 United states

1 个答案:

答案 0 :(得分:2)

目前,无法通过模板化构造函数推断出对象的类型。但是,制造商的功能可以提供帮助:

template<class T>
foobar<T> make_foobar(const T& t) {
    return Foobar<T>(t);
}

...
auto f = make_foobar(foo);
相关问题