@@ -434,9 +434,9 @@ Avoiding Inheritance Slicing and ``std::weak_ptr`` surprises
434
434
When working with classes that use virtual functions and are subclassed
435
435
in Python, special care must be taken when converting Python objects to
436
436
``std::shared_ptr<T> ``. Depending on whether the class uses a plain
437
- ``std::shared_ptr `` holder or ``py::smart_holder ``, the resulting pointer
438
- may either allow inheritance slicing or lead to potentially surprising behavior
439
- when constructing ``std::weak_ptr `` instances.
437
+ ``std::shared_ptr `` holder or ``py::smart_holder ``, the resulting
438
+ `` shared_ptr `` may either allow inheritance slicing or lead to potentially
439
+ surprising behavior when constructing ``std::weak_ptr `` instances.
440
440
441
441
This section explains how ``std::shared_ptr `` and ``py::smart_holder `` manage
442
442
object lifetimes differently, how these differences affect trampoline-derived
@@ -446,9 +446,9 @@ desired behavior.
446
446
When using ``std::shared_ptr `` as the holder type, converting a Python object
447
447
to a ``std::shared_ptr<T> `` (e.g., ``obj.cast<std::shared_ptr<T>>() ``, or simply
448
448
passing the Python object as an argument to a ``.def() ``-ed function) returns
449
- a pointer that shares ownership with the original ``class_ `` holder, usually
450
- preserving object lifetime. However, for Python classes that derive from a
451
- trampoline, if the Python object is destroyed, only the base C++ object may
449
+ a `` shared_ptr `` that shares ownership with the original ``class_ `` holder,
450
+ usually preserving object lifetime. However, for Python classes that derive from
451
+ a trampoline, if the Python object is destroyed, only the base C++ object may
452
452
remain alive, leading to inheritance slicing
453
453
(see `#1333 <https://github.com/pybind/pybind11/issues/1333 >`_).
454
454
0 commit comments