PYBIND11_OVERLOAD_PURE Causing Error #4615
Unanswered
lucasMa0809
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm trying to bind the virtual function myfunc in class B. I have class A forward declared and the full definition of class A is in a separate file. I have the following error:
C:/msys64/home/lucas/CS 5850/testproject/test.cpp:21:9: required from here
C:/msys64/mingw64/include/c++/12.2.0/type_traits:1447:38: error: invalid use of incomplete type 'class A
test.cpp:21:9 is the line where PYBIND11_OVERLOAD_PURE locates.
If myfunc is not a virtual function, I can use A_wrapper to accomplish my goal. However, when myfunc becomes pure virtual, the macro PYBIND11_OVERLOAD_PURE seemed need to check full definition of A. How can I work around this?
Here are my codes:
#include <pybind11/pybind11.h>
namespace py = pybind11;
class A;
class B {
public:
virtual void myfunc(A* p) = 0;
};
struct A_wrapper {
A* ptr;
};
class PyB : B {
public:
void myfunc(A* p) override {
PYBIND11_OVERLOAD_PURE(void, B, myfunc, p)
}
};
PYBIND11_MODULE(mymodule, m) {
py::class_<A_wrapper>(m, "A_wrapper");
py::class_<B, PyB>(m, "B")
.def("myfunc", [](B &self, A_wrapper a) { self.myfunc(a.ptr); });
}
Beta Was this translation helpful? Give feedback.
All reactions