[odb-users] Passing persistence object to smart pointer

Boris Kolpackov boris at codesynthesis.com
Thu Feb 24 09:52:15 EST 2011


Hi,

Bright Dadson <losintikfos at yahoo.co.uk> writes:

> I tried auto_ptr<person> joan(new person());
>
> [...]
> 
> /usr/local/include/odb/database.ixx:40: error: invalid initialization of 
> reference of type ‘person* const&’ from expression of type ‘const 
> std::auto_ptr<person>’

By default ODB assumes the object pointer is the raw pointer (e.g.,
person*). If you want to use auto_ptr as the object pointer, you can
run the ODB compiler with the following option:

--default-pointer std::auto_ptr

Alternatively, if you don't want to change the object pointer, then
you can always pass a reference instead of a pointer to the database
functions, for example:

db->persist (*joan);

Boris



More information about the odb-users mailing list