diff --git a/docs/advanced/cast/stl.rst b/docs/advanced/cast/stl.rst index bbd23732b..16ac0e6de 100644 --- a/docs/advanced/cast/stl.rst +++ b/docs/advanced/cast/stl.rst @@ -72,7 +72,7 @@ functions: /* ... binding code ... */ py::class_(m, "MyClass") - .def(py::init<>) + .def(py::init<>()) .def_readwrite("contents", &MyClass::contents); In this case, properties can be read and written in their entirety. However, an diff --git a/docs/advanced/classes.rst b/docs/advanced/classes.rst index e20895e6d..5843e2447 100644 --- a/docs/advanced/classes.rst +++ b/docs/advanced/classes.rst @@ -186,7 +186,7 @@ example as follows: virtual std::string go(int n_times) = 0; virtual std::string name() { return "unknown"; } }; - class Dog : public class Animal { + class Dog : public Animal { public: std::string go(int n_times) override { std::string result; @@ -228,7 +228,8 @@ declare or override any virtual methods itself: class Husky : public Dog {}; class PyHusky : public Husky { - using Dog::Dog; // Inherit constructors + public: + using Husky::Husky; // Inherit constructors std::string go(int n_times) override { PYBIND11_OVERLOAD_PURE(std::string, Husky, go, n_times); } std::string name() override { PYBIND11_OVERLOAD(std::string, Husky, name, ); } std::string bark() override { PYBIND11_OVERLOAD(std::string, Husky, bark, ); } @@ -242,11 +243,13 @@ follows: .. code-block:: cpp template class PyAnimal : public AnimalBase { + public: using AnimalBase::AnimalBase; // Inherit constructors std::string go(int n_times) override { PYBIND11_OVERLOAD_PURE(std::string, AnimalBase, go, n_times); } std::string name() override { PYBIND11_OVERLOAD(std::string, AnimalBase, name, ); } }; template class PyDog : public PyAnimal { + public: using PyAnimal::PyAnimal; // Inherit constructors // Override PyAnimal's pure virtual go() with a non-pure one: std::string go(int n_times) override { PYBIND11_OVERLOAD(std::string, DogBase, go, n_times); } @@ -373,7 +376,7 @@ crucial that instances are deallocated on the C++ side to avoid memory leaks. /* ... binding code ... */ py::class_>(m, "MyClass") - .def(py::init<>) + .def(py::init<>()) Implicit conversions ==================== @@ -487,6 +490,7 @@ to Python. .def(py::self += py::self) .def(py::self *= float()) .def(float() * py::self) + .def(py::self * float()) .def("__repr__", &Vector2::toString); return m.ptr(); diff --git a/docs/advanced/functions.rst b/docs/advanced/functions.rst index f291e8222..513114458 100644 --- a/docs/advanced/functions.rst +++ b/docs/advanced/functions.rst @@ -207,8 +207,8 @@ For instance, the following statement iterates over a Python ``dict``: void print_dict(py::dict dict) { /* Easily interact with Python types */ for (auto item : dict) - std::cout << "key=" << item.first << ", " - << "value=" << item.second << std::endl; + std::cout << "key=" << std::string(py::str(item.first)) << ", " + << "value=" << std::string(py::str(item.second)) << std::endl; } It can be exported: diff --git a/docs/advanced/pycpp/object.rst b/docs/advanced/pycpp/object.rst index 8fc165d16..8e737cc02 100644 --- a/docs/advanced/pycpp/object.rst +++ b/docs/advanced/pycpp/object.rst @@ -57,7 +57,7 @@ In C++, the same call can be made using: .. code-block:: cpp - using pybind11::literals; // to bring in the `_a` literal + using namespace pybind11::literals; // to bring in the `_a` literal f(1234, "say"_a="hello", "to"_a=some_instance); // keyword call in C++ Unpacking of ``*args`` and ``**kwargs`` is also possible and can be mixed with diff --git a/docs/classes.rst b/docs/classes.rst index 872977684..0bddfe29b 100644 --- a/docs/classes.rst +++ b/docs/classes.rst @@ -298,8 +298,8 @@ different kinds of input arguments: struct Pet { Pet(const std::string &name, int age) : name(name), age(age) { } - void set(int age) { age = age; } - void set(const std::string &name) { name = name; } + void set(int age_) { age = age_; } + void set(const std::string &name_) { name = name_; } std::string name; int age;