Closed
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
the bind code like this :
#include <pybind11/pybind11.h>
#include <iostream>
namespace py = pybind11;
using std::cout;
using std::endl;
class Animal {
public:
virtual ~Animal() { }
virtual void* go() = 0;
};
class PyAnimal : public Animal {
public:
/* Inherit the constructors */
using Animal::Animal;
/* Trampoline (need one for each virtual function) */
void* go() override {
PYBIND11_OVERRIDE_PURE(
void*, /* Return type */
Animal, /* Parent class */
go, /* Name of function in C++ (must match Python name) */
);
}
};
PYBIND11_MODULE(example, m) {
py::class_<Animal, PyAnimal /* <--- trampoline*/>(m, "Animal")
.def(py::init<>())
.def("go", &Animal::go);
}
use pybind11 2.10.0,get error below:
example.cpp: In member function ‘virtual void* PyAnimal::go(int)’:
example.cpp:21:9: error: void value not ignored as it ought to be
21 | PYBIND11_OVERRIDE_PURE(
| ^~~~~~~~~~~~~~~~~~~~~~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
but use pybind 2.9.2 is ok ,how to deal with it ??
Reproducible example code
No response