boost::openmethod::virtual_ptr::virtual_ptr
Construct a virtual_ptr from a pointer to an object
Synopsis
Declared in <boost/openmethod/core.hpp>
template<class Other>
requires IsPolymorphic<Class, Registry> &&
std::is_constructible_v<Class*, Other*>
virtual_ptr(Other* other);
Description
The pointer to the v‐table is obtained by calling boost_openmethod_vptr if a suitable overload exists, or the policies::vptr::fn::dynamic_vptr of the registry's vptr policy otherwise.
Example
struct Animal { virtual ~Animal() { } }; // polymorphic
struct Dog : Animal {}; // polymorphic
BOOST_OPENMETHOD_CLASSES(Animal, Dog);
initialize();
Dog snoopy;
Animal* animal = &snoopy;
virtual_ptr<Animal> p = animal;
BOOST_TEST(p.get() == &snoopy);
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
Requirements
-
`Other` must be a polymorphic class, according to `Registry`'s `rtti` policy.
-
`Other\*` must be constructible from `Class\*`.
Errors
The following errors may occur, depending on the policies selected in Registry:
-
missing_class
Parameters
| Name | Description |
|---|---|
other |
A pointer to a polymorphic object |
Created with MrDocs