[odb-users] Using std::weak_ptr

Boris Kolpackov boris at codesynthesis.com
Fri Aug 3 10:21:20 EDT 2018

Lukas Barth <lists at tinloaf.de> writes:

> main-odb.cxx:794:43: note:   mismatched types ‘std::weak_ptr<_Tp>’ and
> ‘odb::object_traits<Bar>::pointer_type {aka Bar*}’
>              obj_traits::object_type > (id));
> There are three more candidates which I skipped. The important part: ODB
> tries somewhere to create a std::weak_ptr<Bar> from a Bar *, which is
> obviously not possible. It would have to create it from a
> std::shared_ptr<Bar>. However, the ODB documentation explicitly says one
> should (and in fact must) use std::weak_ptr in these cases.
> What am I doing wrong?

You need to make std::shared_ptr the object pointer for your objects.
See Section 3.3, "Object and View Pointers" for details.


More information about the odb-users mailing list