boost::openmethod::virtual_ptr::operator=

Assign a virtual_ptr from a pointer to an object

Synopsis

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

  • `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