[bind] how to get the type after bind
//my question is how to write the type ??? below to make it run . #include <boost/bind.hpp> #include <iostream> using boost::bind; void print() { std::cout <<" print" << std::endl; } template <class T> void func(T t) { std::cout <<"func1(T t) : " ; t(); } int main() { func(bind(&print)); //ok bind ( &func<???>, bind(&print) ) ; //don't know how to write it }
On 2/1/07, hongleij@126.com <hongleij@126.com> wrote:
//my question is how to write the type ??? below to make it run .
#include <boost/bind.hpp> #include <iostream> using boost::bind; void print() { std::cout <<" print" << std::endl; }
template <class T> void func(T t) { std::cout <<"func1(T t) : " ; t(); } int main() { func(bind(&print)); //ok
You don't have to use bind here. func( print ) ; would work. bind ( &func<???>, bind(&print) ) ; //don't know how to write it
}
Note that this expression will not call anything, it will generate a functor and drop it. I guess what you are trying to do is this bind( func<void()>, print) (); // note the function call operator at the end. or maybe this: bind( func<void()>, _1) (print); hth, -- Server Levent Yilmaz Mechanical Engineering @ PITT
On 2/1/07, Server Levent Yilmaz <leventyilmaz@gmail.com> wrote:
Note that this expression will not call anything, it will generate a functor and drop it. I guess what you are trying to do is this
bind( func<void()>, print) (); // note the function call operator at the end.
A more conforming statement would be this: bind( func<void(*)()>, print) (); although first one does work with some compilers (MSVC to be specific, grrr). - levent -- Server Levent Yilmaz Mechanical Engineering @ PITT
participants (2)
-
hongleij@126.com
-
Server Levent Yilmaz