// Copyright (c) 2018-2025 Jean-Louis Leroy // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include using boost::openmethod::virtual_ptr; struct Role { virtual ~Role() { } }; struct Employee : Role { virtual auto pay() -> double; }; struct Manager : Employee { virtual auto pay() -> double; }; struct Founder : Role {}; struct Expense { virtual ~Expense() { } }; struct Public : Expense {}; struct Bus : Public {}; struct Metro : Public {}; struct Taxi : Expense {}; struct PrivateJet : Expense {}; BOOST_OPENMETHOD_CLASSES( Role, Employee, Manager, Founder, Expense, Public, Bus, Metro, Taxi, PrivateJet); BOOST_OPENMETHOD(pay, (virtual_ptr), double); BOOST_OPENMETHOD( approve, (virtual_ptr, virtual_ptr, double), bool); BOOST_OPENMETHOD_OVERRIDE(pay, (virtual_ptr), double) { return 3000; } BOOST_OPENMETHOD_OVERRIDE(pay, (virtual_ptr exec), double) { return next(exec) + 2000; } BOOST_OPENMETHOD_OVERRIDE( approve, (virtual_ptr, virtual_ptr, double), bool) { return false; } BOOST_OPENMETHOD_OVERRIDE( approve, (virtual_ptr, virtual_ptr, double), bool) { return true; } BOOST_OPENMETHOD_OVERRIDE( approve, (virtual_ptr, virtual_ptr, double), bool) { return true; } BOOST_OPENMETHOD_OVERRIDE( approve, (virtual_ptr, virtual_ptr, double), bool) { return true; } auto main() -> int { boost::openmethod::initialize(); } auto call_pay(Employee& emp) -> double { return pay(emp); } auto Employee::pay() -> double { return 3000; } auto Manager::pay() -> double { return Employee::pay() + 2000; } auto call_pay_vfunc(Employee& emp) -> double { return emp.pay(); } auto call_approve(const Role& r, const Expense& e, double a) -> bool { return approve(r, e, a); }