// 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 #include #include #include using namespace boost::openmethod; struct Animal : inplace_vptr_base {}; struct Cat : Animal, inplace_vptr_derived {}; struct Dog : Animal, inplace_vptr_derived {}; BOOST_OPENMETHOD( poke, (virtual_ animal, std::ostream& os), void); BOOST_OPENMETHOD_OVERRIDE(poke, (Cat&, std::ostream& os), void) { os << "hiss\n"; } BOOST_OPENMETHOD_OVERRIDE(poke, (Dog&, std::ostream& os), void) { os << "bark\n"; } int main() { initialize(); std::unique_ptr a = std::make_unique(); std::unique_ptr b = std::make_unique(); poke(*a, std::cout); // hiss poke(*b, std::cout); // bark return 0; }