Skip to content

error: no matching function for call to ‘pybind11::class_<Operations<int> > #2278

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

Closed
matthrx opened this issue Jul 6, 2020 · 1 comment

Comments

@matthrx
Copy link

matthrx commented Jul 6, 2020

Hello,

I am trying to use the pybind11 library with a very basic example. I am trying to apply pybind11 to a template class doing basic operations (for the example). I did research for a long time in order to know whether someone had faced a similar mistake but so far they are fruitless, that's why I decided to open this issue.

Here is the template class Operations (i don't include the cpp file as function are extremely simple)
subtract

And here is the file used to bind it to a python library
binding

When I attempt to install it, I have the following error :
error: no matching function for call to ‘pybind11::class_<Operations >::def(std::__cxx11::basic_string, int (Operations::*)(int, int))’
26 | .def("subtract"+type, &operations::subtract);

Thank you for your time

PS : It is the first time I open an issue, I am sincerely sorry if I was not supposed to do it for this kind of error that I think is only because I did something wrong. Obviously, I looked into the faq.html of pybind11 and found nothing relevant for my case. I didn't add the CMakeLists.txt and the setup.py, I will, if you think the error might come from them.

@YannickJadoul
Copy link
Collaborator

The issue seems to be that class_::def is expecting a const char * as first name argument, and you're giving it a std::string. As far as I can quickly check, I believe name is copied inside of the call to def, so ("add"+type).c_str() might work, but best be careful and check.

PS : It is the first time I open an issue, I am sincerely sorry if I was not supposed to do it for this kind of error that I think is only because I did something wrong. Obviously, I looked into the faq.html of pybind11 and found nothing relevant for my case. I didn't add the CMakeLists.txt and the setup.py, I will, if you think the error might come from them.

No worries; thanks for all the information and self-contained exampled. Since you're asking yourself, two small tips:

  1. If you post code as text (between ```) instead of screenshots, it's a lot easier for other to investigate by copying your code.
  2. For this kind of question, rather than an actual/potential issue with pybind11, there's Gitter

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

No branches or pull requests

2 participants