The following TestClass works:
#include <iostream> #include <boost/function.hpp> #include <boost/bind.hpp> void ext_fun(const float f, int i) { std::cout << f << '\t' << i << std::endl; } template <typename T> class TestClass { public: boost::function <void (const T)> test_fun; }; int main() { TestClass<float> tt; tt.test_fun = std::bind(ext_fun, std::placeholders::_1, 10); tt.test_fun(2.1); return(0); } However, I would prefer to define test_fun as a member function template, i.e., something like
class TestClass { public: template <typename T> boost::function <void (const T)> test_fun; }; But if I do it, I get this compiler error: "error: data member ‘test_fun’ cannot be a member template"
Is it possible to define a member function template using a boost::function? If yes, how?
Thank you
--Matteo
struct Foo { int a; };intostruct Foo { template <typename T> T a; };", which you cannot.boost::function