Reputation: 3410
The compiler is failing to deduct template argument for function pointer.
template< class Function >
class foobar {
Function f;
public:
foobar(Function _f) : f(_f) {}
};
The function definition is
bool foo(string a, string b) {
// SOMETHING
}
I'm getting trouble in the following line
foobar f(foo);
The compiler error
error: missing template arguments before ‘f’
Upvotes: 0
Views: 46
Reputation: 62563
Currently, there is no way to deduce type of the object by templated constructor. However, maker functions can help:
template<class T>
foobar<T> make_foobar(const T& t) {
return Foobar<T>(t);
}
...
auto f = make_foobar(foo);
Upvotes: 2