doubt on boost::bind and boost::function
Hi all I am trying to use boost::function combined with boost::bind in order to be able to pass a callback to another function. The callback I want to pass is a member function of the class. The code is below class CA{ bool IsMemberFunction( const std::string& aLine ){ return true; } void testUseFooPtr( boost::function< bool(const std::string& ) > aFooPtr ){ std::string aLine; // read from somewhere if( aFooPtr( aLine ) ){ std::cout << "is fine" << std::endl; } } void testFooPtr(){ std::string ciao("aa"); boost::function< bool(const std::string& ) > fooPtr( boost::bind( &CA::IsMemberFunction, this ) ); // create // a boost function using the class memebr testUseFooPtr( fooPtr ); // pass it as callback to another // function } }; I have the following compilation error. /usr/local/include/boost/bind/mem_fn.hpp:342: error: invalid use of non-static member function Do you know what I am doing wrong? Is the signature fine? Thanks
If I use _1 it seems that there is a conflict with the placehodler of
boost::lambda
so I switched to using boost::arg<1> to avoid the conflict but I still have
an error saying.
TestBoost_Feb18.h:34: error: expected primary-expression before ‘)’ token
If I want to use the placeholders of boos::bind explicitly ( since I am
using
explicitly boost::bind ) is boost::arg<n> good?
Below is my code
#include
Conoscenza Silente wrote:
Do you know what I am doing wrong? Is the signature fine? Thanks
try boost::bind( &CA::IsMemberFunction, this, _1 )
Cheers,
Rutger
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
P.S. I also tried this one below with unnamed namespace boost::function< bool(const std::string& ) > fooPtr ( boost::bind( &TestBoosFeb18::IsMemberFunction, this, ::_1 ) ); but I have the error error: invalid use of non-static member function On Fri, Feb 19, 2010 at 4:09 PM, Conoscenza Silente < abruzzoforteegentile@gmail.com> wrote:
If I use _1 it seems that there is a conflict with the placehodler of boost::lambda so I switched to using boost::arg<1> to avoid the conflict but I still have an error saying.
TestBoost_Feb18.h:34: error: expected primary-expression before ‘)’ token
If I want to use the placeholders of boos::bind explicitly ( since I am using explicitly boost::bind ) is boost::arg<n> good?
Below is my code #include
boost::function< bool(const std::string& ) > fooPtr ( boost::bind( &CA::IsMemberFunction, this, boost::arg<1> ) );
On Fri, Feb 19, 2010 at 3:31 PM, Rutger ter Borg
wrote: Conoscenza Silente wrote:
Do you know what I am doing wrong? Is the signature fine? Thanks
try boost::bind( &CA::IsMemberFunction, this, _1 )
Cheers,
Rutger
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello, Probably you've meant boost::arg<n>() ? That's because boost::arg<n> is a type, and _1 is a variable. On 19.02.2010 18:09, Conoscenza Silente wrote:
If I use _1 it seems that there is a conflict with the placehodler of boost::lambda so I switched to using boost::arg<1> to avoid the conflict but I still have an error saying.
TestBoost_Feb18.h:34: error: expected primary-expression before ‘)’ token
If I want to use the placeholders of boos::bind explicitly ( since I am using explicitly boost::bind ) is boost::arg<n> good?
Below is my code #include
boost::function< bool(const std::string& ) > fooPtr ( boost::bind( &CA::IsMemberFunction, this, boost::arg<1> ) ); On Fri, Feb 19, 2010 at 3:31 PM, Rutger ter Borg
mailto:rutger@terborg.net> wrote: Conoscenza Silente wrote:
> Do you know what I am doing wrong? > Is the signature fine? > Thanks
try boost::bind( &CA::IsMemberFunction, this, _1 )
Cheers,
Rutger
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
---------------- Sergey Mitsyn.
Auch...It is true.
I switched to boost::arg<1>().
Everything is fine now with both solutions
Thank you very much
CS
On Fri, Feb 19, 2010 at 4:58 PM, Sergey Mitsyn
Hello,
Probably you've meant boost::arg<n>() ? That's because boost::arg<n> is a type, and _1 is a variable.
On 19.02.2010 18:09, Conoscenza Silente wrote:
If I use _1 it seems that there is a conflict with the placehodler of boost::lambda so I switched to using boost::arg<1> to avoid the conflict but I still have an error saying.
TestBoost_Feb18.h:34: error: expected primary-expression before ‘)’ token
If I want to use the placeholders of boos::bind explicitly ( since I am using explicitly boost::bind ) is boost::arg<n> good?
Below is my code #include
boost::function< bool(const std::string& ) > fooPtr ( boost::bind( &CA::IsMemberFunction, this, boost::arg<1> ) ); On Fri, Feb 19, 2010 at 3:31 PM, Rutger ter Borg
mailto:rutger@terborg.net> wrote: Conoscenza Silente wrote:
> Do you know what I am doing wrong? > Is the signature fine? > Thanks
try boost::bind( &CA::IsMemberFunction, this, _1 )
Cheers,
Rutger
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
---------------- Sergey Mitsyn.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Conoscenza Silente
-
Igor R
-
Rutger ter Borg
-
Sergey Mitsyn