boost program options and notifier call

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) { } }; 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? Many thanks in advance! Aljaz

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

()->notifier(boost::bind(&config_class::my_function, this)), "include
Thanks a lot for help! I have no idea why the following code crashes my MSVC optimizing compiler: 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> path"); } void my_function(vector<std::string> str) { } }; Any idea? "Vladimir Prus" <vladimir@codesourcery.com> wrote in message news:g6q7o4$v7h$1@ger.gmane.org...
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
participants (3)
-
Aljaz
-
Steven Watanabe
-
Vladimir Prus