@@ -71,7 +71,7 @@ helper class that is defined as follows:
7171
7272 /* Trampoline (need one for each virtual function) */
7373 std::string go(int n_times) override {
74- PYBIND11_OVERLOAD_PURE (
74+ PYBIND11_OVERRIDE_PURE (
7575 std::string, /* Return type */
7676 Animal, /* Parent class */
7777 go, /* Name of function in C++ (must match Python name) */
@@ -80,10 +80,10 @@ helper class that is defined as follows:
8080 }
8181 };
8282
83- The macro :c:macro: `PYBIND11_OVERLOAD_PURE ` should be used for pure virtual
84- functions, and :c:macro: `PYBIND11_OVERLOAD ` should be used for functions which have
83+ The macro :c:macro: `PYBIND11_OVERRIDE_PURE ` should be used for pure virtual
84+ functions, and :c:macro: `PYBIND11_OVERRIDE ` should be used for functions which have
8585a default implementation. There are also two alternate macros
86- :c:macro: `PYBIND11_OVERLOAD_PURE_NAME ` and :c:macro: `PYBIND11_OVERLOAD_NAME ` which
86+ :c:macro: `PYBIND11_OVERRIDE_PURE_NAME ` and :c:macro: `PYBIND11_OVERRIDE_NAME ` which
8787take a string-valued name argument between the *Parent class * and *Name of the
8888function * slots, which defines the name of function in Python. This is required
8989when the C++ and Python versions of the
@@ -122,7 +122,7 @@ Bindings should be made against the actual class, not the trampoline helper clas
122122
123123 Note, however, that the above is sufficient for allowing python classes to
124124extend ``Animal ``, but not ``Dog ``: see :ref: `virtual_and_inheritance ` for the
125- necessary steps required to providing proper overload support for inherited
125+ necessary steps required to providing proper overriding support for inherited
126126classes.
127127
128128The Python session below shows how to override ``Animal::go `` and invoke it via
@@ -182,15 +182,24 @@ Please take a look at the :ref:`macro_notes` before using this feature.
182182
183183 - because in these cases there is no C++ variable to reference (the value
184184 is stored in the referenced Python variable), pybind11 provides one in
185- the PYBIND11_OVERLOAD macros (when needed) with static storage duration.
186- Note that this means that invoking the overloaded method on *any *
185+ the PYBIND11_OVERRIDE macros (when needed) with static storage duration.
186+ Note that this means that invoking the overridden method on *any *
187187 instance will change the referenced value stored in *all * instances of
188188 that type.
189189
190190 - Attempts to modify a non-const reference will not have the desired
191191 effect: it will change only the static cache variable, but this change
192192 will not propagate to underlying Python instance, and the change will be
193- replaced the next time the overload is invoked.
193+ replaced the next time the override is invoked.
194+
195+ .. warning ::
196+
197+ The :c:macro: `PYBIND11_OVERRIDE ` and accompanying macros used to be called
198+ ``PYBIND11_OVERLOAD `` up until pybind11 v2.5.0, and :func: `get_override `
199+ used to be called ``get_overload ``. This naming was corrected and the older
200+ macro and function names have been deprecated, in order to reduce confusion
201+ with overloaded functions and methods and ``py::overload_cast `` (see
202+ :ref: `_classes `).
194203
195204.. seealso ::
196205
@@ -238,20 +247,20 @@ override the ``name()`` method):
238247 class PyAnimal : public Animal {
239248 public:
240249 using Animal::Animal; // Inherit constructors
241- std::string go(int n_times) override { PYBIND11_OVERLOAD_PURE (std::string, Animal, go, n_times); }
242- std::string name() override { PYBIND11_OVERLOAD (std::string, Animal, name, ); }
250+ std::string go(int n_times) override { PYBIND11_OVERRIDE_PURE (std::string, Animal, go, n_times); }
251+ std::string name() override { PYBIND11_OVERRIDE (std::string, Animal, name, ); }
243252 };
244253 class PyDog : public Dog {
245254 public:
246255 using Dog::Dog; // Inherit constructors
247- std::string go(int n_times) override { PYBIND11_OVERLOAD (std::string, Dog, go, n_times); }
248- std::string name() override { PYBIND11_OVERLOAD (std::string, Dog, name, ); }
249- std::string bark() override { PYBIND11_OVERLOAD (std::string, Dog, bark, ); }
256+ std::string go(int n_times) override { PYBIND11_OVERRIDE (std::string, Dog, go, n_times); }
257+ std::string name() override { PYBIND11_OVERRIDE (std::string, Dog, name, ); }
258+ std::string bark() override { PYBIND11_OVERRIDE (std::string, Dog, bark, ); }
250259 };
251260
252261 .. note ::
253262
254- Note the trailing commas in the ``PYBIND11_OVERLOAD `` calls to ``name() ``
263+ Note the trailing commas in the ``PYBIND11_OVERIDE `` calls to ``name() ``
255264 and ``bark() ``. These are needed to portably implement a trampoline for a
256265 function that does not take any arguments. For functions that take
257266 a nonzero number of arguments, the trailing comma must be omitted.
@@ -266,9 +275,9 @@ declare or override any virtual methods itself:
266275 class PyHusky : public Husky {
267276 public:
268277 using Husky::Husky; // Inherit constructors
269- std::string go(int n_times) override { PYBIND11_OVERLOAD_PURE (std::string, Husky, go, n_times); }
270- std::string name() override { PYBIND11_OVERLOAD (std::string, Husky, name, ); }
271- std::string bark() override { PYBIND11_OVERLOAD (std::string, Husky, bark, ); }
278+ std::string go(int n_times) override { PYBIND11_OVERRIDE_PURE (std::string, Husky, go, n_times); }
279+ std::string name() override { PYBIND11_OVERRIDE (std::string, Husky, name, ); }
280+ std::string bark() override { PYBIND11_OVERRIDE (std::string, Husky, bark, ); }
272281 };
273282
274283 There is, however, a technique that can be used to avoid this duplication
@@ -281,15 +290,15 @@ follows:
281290 template <class AnimalBase = Animal> class PyAnimal : public AnimalBase {
282291 public:
283292 using AnimalBase::AnimalBase; // Inherit constructors
284- std::string go(int n_times) override { PYBIND11_OVERLOAD_PURE (std::string, AnimalBase, go, n_times); }
285- std::string name() override { PYBIND11_OVERLOAD (std::string, AnimalBase, name, ); }
293+ std::string go(int n_times) override { PYBIND11_OVERRIDE_PURE (std::string, AnimalBase, go, n_times); }
294+ std::string name() override { PYBIND11_OVERRIDE (std::string, AnimalBase, name, ); }
286295 };
287296 template <class DogBase = Dog> class PyDog : public PyAnimal<DogBase> {
288297 public:
289298 using PyAnimal<DogBase>::PyAnimal; // Inherit constructors
290299 // Override PyAnimal's pure virtual go() with a non-pure one:
291- std::string go(int n_times) override { PYBIND11_OVERLOAD (std::string, DogBase, go, n_times); }
292- std::string bark() override { PYBIND11_OVERLOAD (std::string, DogBase, bark, ); }
300+ std::string go(int n_times) override { PYBIND11_OVERRIDE (std::string, DogBase, go, n_times); }
301+ std::string bark() override { PYBIND11_OVERRIDE (std::string, DogBase, bark, ); }
293302 };
294303
295304 This technique has the advantage of requiring just one trampoline method to be
@@ -342,7 +351,7 @@ valid for the trampoline class but not the registered class. This is primarily
342351for performance reasons: when the trampoline class is not needed for anything
343352except virtual method dispatching, not initializing the trampoline class
344353improves performance by avoiding needing to do a run-time check to see if the
345- inheriting python instance has an overloaded method.
354+ inheriting python instance has an overridden method.
346355
347356Sometimes, however, it is useful to always initialize a trampoline class as an
348357intermediate class that does more than just handle virtual method dispatching.
@@ -373,7 +382,7 @@ references (See also :ref:`faq_reference_arguments`). Another way of solving
373382this is to use the method body of the trampoline class to do conversions to the
374383input and return of the Python method.
375384
376- The main building block to do so is the :func: `get_overload `, this function
385+ The main building block to do so is the :func: `get_override `, this function
377386allows retrieving a method implemented in Python from within the trampoline's
378387methods. Consider for example a C++ method which has the signature
379388``bool myMethod(int32_t& value) ``, where the return indicates whether
@@ -385,10 +394,10 @@ Python side by allowing the Python function to return ``None`` or an ``int``:
385394 bool MyClass::myMethod(int32_t& value)
386395 {
387396 pybind11::gil_scoped_acquire gil; // Acquire the GIL while in this scope.
388- // Try to look up the overloaded method on the Python side.
389- pybind11::function overload = pybind11::get_overload (this, "myMethod");
390- if (overload ) { // method is found
391- auto obj = overload (value); // Call the Python function.
397+ // Try to look up the overridden method on the Python side.
398+ pybind11::function override = pybind11::get_override (this, "myMethod");
399+ if (override ) { // method is found
400+ auto obj = override (value); // Call the Python function.
392401 if (py::isinstance<py::int_>(obj)) { // check if it returned a Python integer type
393402 value = obj.cast<int32_t>(); // Cast it and assign it to the value.
394403 return true; // Return true; value should be used.
@@ -1065,7 +1074,7 @@ described trampoline:
10651074
10661075 class Trampoline : public A {
10671076 public:
1068- int foo() const override { PYBIND11_OVERLOAD (int, A, foo, ); }
1077+ int foo() const override { PYBIND11_OVERRIDE (int, A, foo, ); }
10691078 };
10701079
10711080 class Publicist : public A {
0 commit comments