[odb-users] Compile error in XXX-odb.cxx when exchanging std::weak_ptr for odb::lazy_weak_ptr

dieter.govaerts at bricsys.com dieter.govaerts at bricsys.com
Fri Mar 18 10:44:26 EDT 2016


Hi,

I'm experiencing following compile error on Visual Studio 2013 when I exchange a std::weak_ptr for a odb::lazy_weak_ptr:

D:\\Dev\\shared\\thirdparty\\libodb\\include\odb/traits.hxx(178) : error C2504: 'odb::access::object_traits_impl<T,id_sqlite>' : base class undefined
        with
        [
            T=const Employer
        ]
... [see build.txt in attachment for full listing]

The problem is resolved when I remove the 'const' from the template argument. I like to have it with the 'const' however. How can I resolve this?

Best regards,
Dieter Govaerts


(see attachment for the full sample)

// test.h

#define LAZY_PTR
#ifdef LAZY_PTR
//#define NO_CONST
#endif

class Employee;
typedef std::shared_ptr<Employee> EmployeePtr;
typedef std::shared_ptr<const Employee> ConstEmployeePtr;

class Employer;
typedef std::shared_ptr<Employer> EmployerPtr;
typedef std::shared_ptr<const Employer> ConstEmployerPtr;

#pragma db object transient session
class Employee
    : public std::enable_shared_from_this<Employee>
{
public:
    ...
private:
    #pragma db id auto
    #pragma db member(id) virtual(unsigned int) get(this.impl().m_id) set(const_cast< unsigned int & >(this.impl().m_id))
#ifdef LAZY_PTR
#ifdef NO_CONST
    typedef odb::lazy_weak_ptr< Employer > employer_type;
#else
    typedef odb::lazy_weak_ptr< const Employer > employer_type;
#endif
#else
    typedef std::weak_ptr< const Employer > employer_type;
#endif
    #pragma db inverse(employees)
    #pragma db member(employer) virtual(employer_type) access(this.impl().m_employer)
    #pragma db member(name) virtual(std::string) access(this.impl().m_name)

    friend class odb::access;

protected:
    class Impl;
    const Impl & impl() const;
    Impl & impl();

private:
    Impl * const impl_;
};


// test_impl.h

#include "test.h"

class Employee::Impl
{
public:
    Impl();
    Impl(const Impl &);
#ifdef NO_CONST
    Impl(EmployerPtr const&, std::string const&);
#else
    Impl(ConstEmployerPtr const&, std::string const&);
#endif

public:
    unsigned int const m_id;
#ifdef LAZY_PTR
#ifdef NO_CONST
    odb::lazy_weak_ptr< Employer > m_employer;
#else
    odb::lazy_weak_ptr< const Employer > m_employer;
#endif
#else
    std::weak_ptr< const Employer > m_employer;
#endif
    std::string m_name;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: odb_test.zip
Type: application/x-zip-compressed
Size: 94674 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20160318/855d7c03/odb_test-0001.bin


More information about the odb-users mailing list