Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu::Insert method does not work with free functions and with std::bind. #91

Open
hanyukang opened this issue Jan 27, 2021 · 2 comments

Comments

@hanyukang
Copy link
Contributor

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

@daniele77
Copy link
Owner

@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 :-)

@daniele77 daniele77 changed the title Is it possible to bind a member function to Menu? Menu::Insert method does not work with free functions and with std::bind. Jan 28, 2021
@daniele77
Copy link
Owner

Free function works with commit 63eb029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants