general cleanup of the codebase
- new pybind11::base<> attribute to indicate a subclass relationship
- unified infrastructure for parsing variadic arguments in class_ and cpp_function
- use 'handle' and 'object' more consistently everywhere
diff --git a/example/example5.cpp b/example/example5.cpp
index cabd847..ad24ef0 100644
--- a/example/example5.cpp
+++ b/example/example5.cpp
@@ -29,6 +29,11 @@
void bark() const { std::cout << "Woof!" << std::endl; }
};
+class Rabbit : public Pet {
+public:
+ Rabbit(const std::string &name) : Pet(name, "parrot") {}
+};
+
void pet_print(const Pet &pet) {
std::cout << pet.name() + " is a " + pet.species() << std::endl;
}
@@ -62,9 +67,14 @@
.def("name", &Pet::name)
.def("species", &Pet::species);
+ /* One way of declaring a subclass relationship: reference parent's class_ object */
py::class_<Dog>(m, "Dog", pet_class)
.def(py::init<std::string>());
+ /* Another way of declaring a subclass relationship: reference parent's C++ type */
+ py::class_<Rabbit>(m, "Rabbit", py::base<Pet>())
+ .def(py::init<std::string>());
+
m.def("pet_print", pet_print);
m.def("dog_bark", dog_bark);