boost::openmethod::virtual_ptr<SmartPtr, Registry>::virtual_ptr
Construct from a smart virtual (const) pointer to a derived class
Synopsis
Declared in <boost/openmethod/core.hpp>
template<class Other>
requires SameSmartPtr<SmartPtr, Other, Registry> &&
std::is_constructible_v<SmartPtr, const Other&>
virtual_ptr(virtual_ptr<Other, Registry> const& other);
Description
Copy the object and v‐table pointers from other.
Other is not required to be a pointer to a polymorphic class.
Example
struct Animal {}; // polymorphism not required
struct Dog : Animal {}; // polymorphism not required
BOOST_OPENMETHOD_CLASSES(Animal, Dog);
initialize();
const virtual_ptr<std::shared_ptr<Dog>> snoopy = make_shared_virtual<Dog>();
virtual_ptr<std::shared_ptr<Animal>> p = snoopy;
BOOST_TEST(snoopy.get() != nullptr);
BOOST_TEST(p.get() == snoopy.get());
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
Requirements
-
SmartPtrandOthermust be instantiated from the same template ‐ e.g. bothstd::shared_ptror bothstd::unique_ptr. -
Othermust be a virtual pointer to a class derived fromelement_type. -
SmartPtrmust be constructible fromOther&.
Created with MrDocs