boost::openmethod::virtual_ptr::operator=
Assign a virtual_ptr from a reference to an object
Synopsis
Declared in <boost/openmethod/core.hpp>
template<class Other>
requires IsPolymorphic<Class, Registry> &&
std::is_assignable_v<Class*&, Other*>
virtual_ptr&
operator=(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();
virtual_ptr<Animal> p{nullptr};
Dog snoopy;
Animal& animal = snoopy;
p = animal;
BOOST_TEST(p.get() == &snoopy);
BOOST_TEST(p.vptr() == default_registry::static_vptr<Dog>);
Requirements
-
Othermust be a polymorphic class, according toRegistry'srttipolicy. -
Other*must be constructible fromClass*.
Parameters
| Name | Description |
|---|---|
other |
A reference to a polymorphic object |
Created with MrDocs