-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bindings for copy constructors for classes with Python call-back structure #202
Copy link
Copy link
Closed
Description
Hi Wenzel, I noticed that attempt to bind copy constructors for classes that binded though Python call-back structure (like example12) gives a compilation error. However changing constructor argument type from original class to type-of-call-back structure fixes the error. Is this expect behavior? If so, then perhaps it is a good idea to mention this in docs?
Here is code for modified init_ex12 from PyBind11 example12 to demonstrate this issue. Uncommenting the line .def(py::init<Example12 const &>()) (and commenting out .def(py::init<PyExample12 const &>())) will lead to a compilation error. (rest of example12 code is unchanged)
void init_ex12(py::module &m) {
/* Important: use the wrapper type as a template
argument to class_<>, but use the original name
to denote the type */
py::class_<PyExample12>(m, "Example12")
/* Declare that 'PyExample12' is really an alias for the original type 'Example12' */
.alias<Example12>()
.def(py::init<int>())
//.def(py::init<Example12 const &>()) // give compilation error
.def(py::init<PyExample12 const &>()) // works fine
/* Reference original class in function definitions */
.def("run", &Example12::run)
.def("run_bool", &Example12::run_bool)
.def("pure_virtual", &Example12::pure_virtual);
m.def("runExample12", &runExample12);
m.def("runExample12Bool", &runExample12Bool);
m.def("runExample12Virtual", &runExample12Virtual);
}Thanks,
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels