Boost logo

Boost Users :

From: Vladimir Prus (vladimir_at_[hidden])
Date: 2008-07-30 13:17:48


Aljaz wrote:

> Hello
>
> I have boost.program_options implemented inside a config class.
>
> I want to call function (my_function) that is a member of config class for
> specific option (with notifier call).
>
> class config_class {
> public:
> void read_config() {
> po::options_description desc("Allowed options");
> desc.add_options()
> ("help", "produce help message")
> ("include-path,I", po::value< vector<string>
> >()->notifier(&config_class::my_function), "include path");
> }
>
> void my_function(vector<std::string> str) { }

Don't pass vector by value. Further, the notifier method is documented
thusly:

        typed_value * notifier(function1< void, const T & > f) ;
        Specifies a function to be called when the final value is determined.

So you better make the parameter const -- you won't be able to modify it
anyway.

> };
>
>
> This wont compile and will give error for
> ..>()->notifier(&config_class::my_function)...
> >> error C2064: term does not evaluate to a function taking 1 arguments
>
> What am I doing wrong?

You are passing function with two parameters ("this" and "str") where a function
taking one parameter is expected. Use:

        boost::bind(&config_class::my_function, this)

- Volodya


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net