Menu::Insert method does not work with free functions and with std::bind.
Hi,
Thanks for this great work, One thing I've tried to achieve is to bind a member function to the Menu, but I'm getting an error message:
error C2661: 'cli::Menu::Insert': no overloaded function takes 5 arguments
void TestClass::Test(std::ostream& out)
{
out << "test" << endl;
}
auto func = std::bind(&TestClass::Test, this, std::placeholders::_1);
rootMenu->Insert("test", func, "this is a test");
Am I doing something wrong? No matter how I tried always this error.
Is it possible to bind a member function instead of a lambda function?
Thanks
@hanyukang thank you very much.
Currently, the Menu::Insert method does not work with std::bind (and unfortunately it does not work with free functions, either).
While I understand why free functions are not accepted (they don't have operator () as required by the Menu::Insert method), I must investigate deeply why std::bind is not accepted.
My idea would be to fix this issue (for both cases). Of course, in the meantime, you can wrap your method call in a lambda as a workaround:
rootMenu->Insert(
"test",
[this](std::ostream& out)){ this->Test(out); },
"this is a test"
);
If you like this library add a star (we're almost at 500 :-) ) and please consider becoming a sponsor to support our work by clicking the heart button at the top of the page :-)
Free function works with commit 63eb029