boost::openmethod::weak_virtual_ptr::pointer

Get the weak pointer to the object

Synopsis

Declared in <boost/openmethod/interop/std_weak_ptr.hpp>

std::weak_ptr<Class> const&
pointer() const noexcept;

Example

struct Animal {
    virtual ~Animal() = default;
};
struct Dog : Animal {};
struct Cat : Animal {};

BOOST_OPENMETHOD_CLASSES(Animal, Dog, Cat);

shared_virtual_ptr<Animal> animal = make_shared_virtual<Dog>();
weak_virtual_ptr<Animal> observer = animal;
std::weak_ptr<Animal> weak = observer.pointer();

BOOST_TEST(animal.pointer().use_count() == 1);
BOOST_TEST(weak.lock() == animal.pointer());

Return Value

A const reference to the std::weak_ptr

Created with MrDocs