user3238415
user3238415

Reputation: 328

non standard - use '&' to create pointer to member

Forgive any ignorance, I'm new to c++.

Full error message:

coog.cpp(74): error C3867: 'Manager::start_foo': non-standard syntax; use '&' to create a pointer to member

I'm using boost command line and I'm trying to pass a object member function for the notifier. I've tried a variety of things from different posts on here and google but haven't had any luck. The error message is in the title.

Hopefully this will give you a idea of what I'm trying to do:

Manager manager;

void coog::handle::start(std::vector<char const*>& args, Manager& m)
{
    po::options_description desc("Start allowed options");
    desc.add_options()
        ("foo,f", po::value<std::vector<std::string>>()
            ->multitoken()->notifier(m.start_foo), "start foo(s)")
        ("example", "display an example of how to use each command")
        ("help", "display this message")
    ;

    po::variables_map vm;
    po::store(po::command_line_parser(args.size(), args.data()).
        options(desc).run(), vm);
    po::notify(vm);

}

coog::handle::start(foos, manager);

Any help and explanation would be appreciated.

Upvotes: 0

Views: 478

Answers (1)

ForEveR
ForEveR

Reputation: 55897

notifier is function with this signature:

typed_value * notifier(function1< void, const T & > f);

You cannot just put here class-method, cause it's not suitable for this signature, you can use boost::bind, lambda, or something else, that will allow you to construct function1 with signature specified above from your class-method.

Example with bind:

notifier(boost::bind(&Manager::start_foo, boost::ref(m), _1))

Example with lambda:

notifier([&m](const T& v) { return m.start_foo(v); })

That also depends on start_foo signature, you may need to bind more values.

Upvotes: 3

Related Questions