[odb-users] weak_ptr and default pointer type

Daniel James danielpeterjames at gmail.com
Thu May 3 20:50:25 EDT 2012


Hi

Sorry, this question is a bit basic :)

Is it possible to have the following sort of relationship with the default
pointer type?

#pragma db object pointer(*)
class A {
...
std::weak_ptr<B> b;
...
}
#pragma db object pointer(*)
class B {
...
std::shared_ptr<A> a;
...
}

I tried the above and a compile time error points to the following in the
generated code:

        // If a compiler error points to the line below, then
        // it most likely means that a pointer used in a member
        // cannot be initialized from an object pointer.
        //
        o.a = ptr_traits::pointer_type (
          db->load< obj_traits::object_type > (id));

It's not explicit in the docs that this is not possible but I suppose it is
a consequence of std::weak_ptr's constructors?

Daniel


More information about the odb-users mailing list