@ -104,6 +104,8 @@ With the above change, the same Python code now produces the following output:
@@ -104,6 +104,8 @@ With the above change, the same Python code now produces the following output:
>>> print(p)
<example.Pet named 'Molly'>
..[#f1] Stateless closures are those with an empty pair of brackets ``[]`` as the capture object.
.._properties:
Instance and static fields
@ -337,6 +339,35 @@ The overload signatures are also visible in the method's docstring:
@@ -337,6 +339,35 @@ The overload signatures are also visible in the method's docstring:
|
| Set the pet's name
If you have a C++14 compatible compiler [#cpp14]_, you can use an alternative
syntax to cast the overloaded function:
..code-block:: cpp
py::class_<Pet>(m, "Pet")
.def("set", py::overload_cast<int>(&Pet::set), "Set the pet's age")
.def("set", py::overload_cast<const std::string &>(&Pet::set), "Set the pet's name");
Here, ``py::overload_cast`` only requires the parameter types to be specified.
The return type and class are deduced. This avoids the additional noise of
``void (Pet::*)()`` as seen in the raw cast. If a function is overloaded based
on constness, the ``py::const_`` tag should be used: