[odb-users] Compile Error with Lazy Pointers

EDDOWES Scott scott.eddowes at hds.leica-geosystems.com
Tue Sep 14 12:57:07 EDT 2021


I am having trouble getting lazy pointers to compile using ODB 2.4.0. I am setting the default pointer type to std::shared_ptr for my object classes (though possibly not correctly?).
Please let me know what I can do to resolve this problem.

Thanks!

Example code:

#include <odb/core.hxx>
#include <odb/lazy-ptr.hxx>

#pragma db object pointer(std::shared_ptr)
class foo
{
public:
  foo(int value = 0) : mValue(value) {}
  ~foo() {}

#pragma db id
  int mId;
  int mValue;
};

#pragma db object pointer(std::shared_ptr)
class bar
{
public:
  bar() {}
  ~bar() {}

  void SetFoo(std::shared_ptr<foo>& rpFoo)
  {
    mpFoo = rpFoo;
  }

  bool GetFooVal(int& rValue)
  {
    mpFoo.load();
    if (mpFoo == nullptr)
    {
      return false;
    }
    rValue = mpFoo->mValue;
    return true;
  }

#pragma db id
  int mId;
  odb::lazy_shared_ptr<foo> mpFoo;
};

When I compile this in Visual Studio 2017, I get the following errors:

1>------ Build started: Project: LazyPointerExample, Configuration: Debug x64 ------
1>Generating OdbGen/foobar-odb.cxx, OdbGen/foobar-odb.hxx, OdbGen/foobar-odb.ixx
1>In file included from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:668:0,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx: In instantiation of 'std::shared_ptr<_Tp1> odb::lazy_shared_ptr<T>::load() const [with T = foo]':
1>D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:30:16:   required from here
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx(1153,10): error G199EB5A7: no match for 'operator=' (operand types are 'std::shared_ptr<foo>' and 'odb::object_traits<foo>::pointer_type {aka foo*}')
1>       p_ = i_.template load<T> (true); // Reset id.
1>          ^
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx:1153:10: note: candidates are:
1>In file included from q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\memory:82:0,
1>                 from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:10,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:93:11: note: std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(const std::shared_ptr<_Tp>&) [with _Tp = foo]
1>     class shared_ptr : public __shared_ptr<_Tp>
1>           ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:93:11: note:   no known conversion for argument 1 from 'odb::object_traits<foo>::pointer_type {aka foo*}' to 'const std::shared_ptr<foo>&'
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:272:2: note: template<class _Tp1> std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(const std::shared_ptr<_Tp1>&) [with _Tp1 = _Tp1; _Tp = foo]
1>  operator=(const shared_ptr<_Tp1>& __r) noexcept
1>  ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:272:2: note:   template argument deduction/substitution failed:
1>In file included from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:668:0,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx:1153:10: note:   mismatched types 'const std::shared_ptr<_Tp1>' and 'odb::object_traits<foo>::pointer_type {aka foo*}'
1>       p_ = i_.template load<T> (true); // Reset id.
1>          ^
1>In file included from q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\memory:82:0,
1>                 from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:10,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:281:2: note: template<class _Tp1> std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(std::auto_ptr<_Up>&&) [with _Tp1 = _Tp1; _Tp = foo]
1>  operator=(std::auto_ptr<_Tp1>&& __r)
1>  ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:281:2: note:   template argument deduction/substitution failed:
1>In file included from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:668:0,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx:1153:10: note:   mismatched types 'std::auto_ptr<T>' and 'odb::object_traits<foo>::pointer_type {aka foo*}'
1>       p_ = i_.template load<T> (true); // Reset id.
1>          ^
1>In file included from q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\memory:82:0,
1>                 from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:10,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:289:7: note: std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(std::shared_ptr<_Tp>&&) [with _Tp = foo]
1>       operator=(shared_ptr&& __r) noexcept
1>       ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:289:7: note:   no known conversion for argument 1 from 'odb::object_traits<foo>::pointer_type {aka foo*}' to 'std::shared_ptr<foo>&&'
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:297:2: note: template<class _Tp1> std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(std::shared_ptr<_Tp1>&&) [with _Tp1 = _Tp1; _Tp = foo]
1>  operator=(shared_ptr<_Tp1>&& __r) noexcept
1>  ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:297:2: note:   template argument deduction/substitution failed:
1>In file included from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:668:0,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx:1153:10: note:   mismatched types 'std::shared_ptr<_Tp1>' and 'odb::object_traits<foo>::pointer_type {aka foo*}'
1>       p_ = i_.template load<T> (true); // Reset id.
1>          ^
1>In file included from q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\memory:82:0,
1>                 from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:10,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:305:2: note: template<class _Tp1, class _Del> std::shared_ptr<_Tp>& std::shared_ptr<_Tp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Tp1 = _Tp1; _Del = _Del; _Tp = foo]
1>  operator=(std::unique_ptr<_Tp1, _Del>&& __r)
1>  ^
1>q:\buildsdk\odb\2.4.0\odb-2.4.0-i686-windows\mingw\include\c++\4.9.3\bits\shared_ptr.h:305:2: note:   template argument deduction/substitution failed:
1>In file included from Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.hxx:668:0,
1>                 from D:/Labs/ODB/lazy_pointer_hell/src/foobar.hxx:2:
1>Q:/BuildSdk/ODB/2.4.0/include/odb/lazy-ptr.ixx:1153:10: note:   mismatched types 'std::unique_ptr<_Tp, _Dp>' and 'odb::object_traits<foo>::pointer_type {aka foo*}'
1>       p_ = i_.template load<T> (true); // Reset id.
1>          ^
1>Done building project "LazyPointerExample.vcxproj" -- FAILED.
2>------ Skipped Build: Project: ALL_BUILD, Configuration: Debug x64 ------
2>Project not selected to build for this solution configuration
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 1 skipped ==========


More information about the odb-users mailing list