I have already designed a cpp
shared lib and now I want to make a Python
wrapper to use it. Everything was working fine, until It was necessary to change the cpp
library constructor adding one parameter on it.
I would like to know how reflect this parameter in the wrapper, because the code bellow doesn't work anymore. I have made some changes in the code and now it is like bellow. I am almost sure that the problem is in this line
py::class_<Wrapper>("Wrapper", py::init<>())
but I don't know how to add a parameter here. I tried
py::class_<Wrapper>("Wrapper", py::init<>(const std::string ¶m))
and also
py::class_<Wrapper>("Wrapper", py::init<const std::string ¶m>())
but both failed.
EDIT after some comments, I decided to use (without reference)
py::class_<Wrapper>("Wrapper", py::init<const std::string param>())
But I still have the same error message.
wrapper.hpp
#include "mycpplib.hpp"
#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
#include <boost/python/dict.hpp>
namespace py = boost::python;
namespace np = boost::python::numpy;
class Wrapper
{
public:
// change: inclusion of the new parameter
Wrapper(const std::string ¶m);
py::dict function1();
};
wrapper.cpp
#include "wrapper.hpp"
namespace py = boost::python;
namespace np = boost::python::numpy;
// change: inclusion of the new parameter
Wrapper::Wrapper(
const std::string ¶m) {
//do something
}
py::dict
Wrapper::function1() {
//do something
}
BOOST_PYTHON_MODULE(libwrapper)
{
Py_Initialize();
np::initialize();
py::class_<Wrapper>("Wrapper", py::init<const std::string param1>())
.def("_function1", &Wrapper::function1)
;
}
wrapper.py
import libwrapper
class Wrapper(libwrapper.Wrapper):
# change: inclusion of the new parameter
def __init__(self, param):
libwrapper.Wrapper.__init__(self, param)
def function1(self):
return self._function1()
The error is:
/path/wrapper.cpp: In function 'void init_module_libwrapper()':
/path/wrapper.cpp:24:69: error: template argument 1 is invalid
py::class_<Wrapper>("Wrapper", py::init<const std::string param1>())
^