[odb-users] Trouble with lazy_ptr

Boris Kolpackov boris at codesynthesis.com
Sun Aug 19 10:58:16 EDT 2012


Hi Miguel,

> /usr/include/odb/lazy-ptr.ixx:1511:5: error: no match for 'operator='
> in 'r = ((const odb::lazy_weak_ptr<user>*)this)->odb::lazy_weak_ptr<user>::i_.odb::lazy_ptr_impl<T>::load<user>(0)'

I believe this error is due to the incompatible canonical object
pointer used for your 'node' and 'user' classes (see Section 3.2,
"Object and View Pointers" for more information). Specifically,
your 'node' class uses the raw pointer (node*) as the object pointer.
This is incompatible with all the C++11 shared/weak pointers that
you are using in object relationships. So what you need to do is
use std::shared_ptr as your object pointer:

#pragma db object polymorphic pointer(std::shared_ptr)
class node {
  ...
};

Alternatively, you may want to make all your objects use std::shared_ptr
as object pointer by default (this way, if you add another class, you
won't need to worry about forgetting to add the pointer pragma). This
can be done with the --default-pointer ODB compiler option, for example:

--default-pointer std::shared_ptr

Boris



More information about the odb-users mailing list