I currently have a templated class, with a templated method. Works great with functors, but having trouble compiling for functions.
Foo.h
template <typename T>
class Foo {
public:
// Constructor, destructor, etc...
template <typename Func>
void bar(T x, Func f);
};
template <typename T>
template <typename Func>
void Foo<T>::bar(T x, Func f) { /* some code here */ }
Main.cpp
#include "Foo.h"
template <typename T>
class Functor {
public:
Functor() {}
void operator()(T x) { /* ... */ }
private:
/* some attributes here */
};
template <typename T>
void Function(T x) { /* ... */ }
int main() {
Foo<int> foo;
Functor<int> F;
foo.bar(2, F); // No problem
foo.bar(2, Function); // <unresolved overloaded function type>
return 0;
}
If you want to get a function pointer for an overloaded function, you need to tell the system which function out of the overload set you want:
In the quoted case the function is actually a template, i.e., you can also refer to its specialization directly: