[Boost-users] [program_options] How to use "notifier" in options_description with member functions?

144 views
Skip to first unread message

Carlos Franke

unread,
Oct 24, 2010, 6:06:34 PM10/24/10
to boost...@lists.boost.org
Hello!

I am looking for advice about the use of the "notifier" function in program_options::options_description with class methods. My problem seems very basic to mee, yet I wasn't able to find the (any) related documentation.

Here is a minimal example of what I cannot get to work:

struct test
{
void function(int i) {std::cout << i << std::endl;}

void does_not_compile()
{
po::options_description desc;
desc.add_options()
("option", po::value<int>()->notifier(&test::function), "Option")
;
}
};

Compilation fails with:
[…]
test.cpp:62:82: instantiated from here
/usr/include/boost/function/function_template.hpp:225:11: error: no match for call to '(boost::_mfi::mf1<void, test, int>) (const int&)'
/usr/include/boost/bind/mem_fn_template.hpp:163:7: note: candidates are: R boost::_mfi::mf1<R, T, A1>::operator()(T*, A1) const [with R = void, T = test, A1 = int]
/usr/include/boost/bind/mem_fn_template.hpp:184:7: note: R boost::_mfi::mf1<R, T, A1>::operator()(T&, A1) const [with R = void, T = test, A1 = int]

Sorry if this is trivial. Your help is all the more appreciated!

Carlos

signature.asc

jiang...@gmail.com

unread,
Oct 24, 2010, 10:01:02 PM10/24/10
to boost...@lists.boost.org
try this with boost::bind

           ("option", po::value<int>()->notifier(
               boost::bind(&test::function, this, _1)), "Option")

                                                      Changsheng Jiang


_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Carlos Franke

unread,
Oct 25, 2010, 5:30:18 AM10/25/10
to boost...@lists.boost.org
> ("option", po::value<int>()->notifier(
> boost::bind(&test::function, this, _1)), "Option")

Thanks, that is what I was looking for.

Carlos

signature.asc
Reply all
Reply to author
Forward
0 new messages