BOOST_OPENMETHOD_INLINE_OVERRIDE

Add an overrider to a method as an inline function.

Synopsis

Declared in <boost/openmethod/macros.hpp>

#define BOOST_OPENMETHOD_INLINE_OVERRIDE(ID, PARAMETERS, …​)

Description

BOOST_OPENMETHOD_INLINE_OVERRIDE performs the same function as BOOST_OPENMETHOD_OVERRIDE, except that the overrider is marked inline.

Use it for an overrider defined in a header, where the same definition reaches more than one translation unit. inline is what makes the repeated definition legal, and it lets boost::openmethod::initialize merge the repeated registrations. BOOST_OPENMETHOD_OVERRIDE would instead record them as distinct overriders for the same class, making the call ambiguous.

ID must be an identifier. Qualified names are not allowed.

Example

A header that declares a method and supplies a default overrider for it. Every translation unit including it gets the same definition:

// roles.hpp

#ifndef ROLES_HPP
#define ROLES_HPP

#include <boost/openmethod.hpp>

struct Employee { virtual ~Employee() = default; };

struct Salesman : Employee {
    double sales = 0.0;
};

BOOST_OPENMETHOD(pay, (boost::openmethod::virtual_ptr<const Employee>), double);

BOOST_OPENMETHOD_INLINE_OVERRIDE(
    pay, (boost::openmethod::virtual_ptr<const Employee>), double) {
    return 5000.0;
}

#endif // ROLES_HPP

A translation unit that includes the header adds a more specialized overrider of its own. That one is defined once, so it uses BOOST_OPENMETHOD_OVERRIDE; it reaches the header's overrider through BOOST_OPENMETHOD_OVERRIDER

BOOST_OPENMETHOD_OVERRIDE(
    pay, (boost::openmethod::virtual_ptr<const Salesman> emp), double) {
    return BOOST_OPENMETHOD_OVERRIDER(
               pay, (boost::openmethod::virtual_ptr<const Employee> emp),
               double)::fn(emp) +
        emp->sales * 0.05; // base + commission
}

Parameters

Name

Description

ID

The method's name.

PARAMETERS

The overrider's parameter list, in parentheses.

...

The overrider's return type.

See Also