[odb-users] Problem with many-to-many example
Tom Stoffer
tomstoffer at gmail.com
Tue Jul 12 18:41:16 EDT 2016
Hi,
I have been diving deep into ODB over the past few days. Trying to wrap my head around the various relation types etc. I have copied the following code from your example in the manual:
=======================================================
class project;
#pragma db object
class employee
{
friend class odb::access;
public:
employee() {};
#pragma db id
std::string uid;
#pragma db value_not_null unordered
std::vector<std::shared_ptr<project> > projects_;
};
#pragma db object
class project
{
friend class odb::access;
public:
project () {};
#pragma db id
std::string uid;
#pragma db value_not_null inverse(projects_)
std::vector<std::weak_ptr<employee>> employees_;
};
=======================================================
However it does not compile on OSX with Xcode, I getting a compile error:
No matching conversion for functional-style cast from 'typename object_traits<employee>::pointer_type' (aka 'employee *') to 'ptr_traits::pointer_type' (aka 'weak_ptr<employee>')
And I have noticed the comment:
// 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.
I have read all through this mailing list for similar issues and everything in the manual related, still no luck. Im sure its something simple, please could you advise.
The one thing that does get it to compile is if I add: pointer(std::shared_ptr) To the pragma for employee, but I’m not sure why, and actually I don’t think this will work for my situation as the class which will be needed to have a many-to-many also inheriting from an abstract polymorphism. As soon as I introduce this change, I start getting other compiler errors to do with shared_ptr not being supported.
Tom
More information about the odb-users
mailing list