[odb-users] Multiple pointer types in a single object
Boris Kolpackov
boris at codesynthesis.com
Tue Oct 4 13:24:03 EDT 2011
Hi Thomas,
Szumowski, Thomas <thomas.szumowski at lmco.com> writes:
> Suppose I have a class that requires relationships to two different
> objects. One relationship requires weak_ptr, and one requires shared_ptr.
> Is this possible?
Yes, this is not a problem.
> We noticed one can assign the pointer type at the object level,
> ("#pragma db object pointer"), but what if we want multiple pointer
> types in a single object? e.g (for example purpose only)
>
> class employee {
> ...
> shared_ptr<employer> e;
> weak_ptr<project> p;
> }
>
> Is this possible?
Yes, the object pointer that is assigned via db pointer pragma or
using the --default-pointer option is what is used to return such
objects from load(), etc. It should normally be a shared_ptr. But
in object relationships you can use any pointer type as long as
it can be created from the object pointer. So weak_ptr should not
cause any problem here. You can even have something like this:
class employee
{
shared_ptr<employer> current_employer;
weak_ptr<employer> previous_employer;
}
Boris
More information about the odb-users
mailing list