[odb-users] Problems with iterating results

Harrie9 harriev9 at gmail.com
Thu Nov 13 16:11:27 EST 2014


Hello,

When I compile:



#include <vector>
#include <memory>   // std::auto_ptr
#include <iostream>

#include <odb/database.hxx>
#include <odb/transaction.hxx>

#include <odb/pgsql/database.hxx>

#include "relation.h"
#include "relation-odb.hxx"

using namespace std;
using namespace odb::core;

int
main (int argc, char* argv[])
{
  try
  {
    auto_ptr<database> db (new odb::pgsql::database (argc, argv));

    unsigned long relation_id;

    // Create a few persistent person objects.
    
    {
       relation john ("Jhon", "Deer", "Hevel", "12", "City",
"04556342","xx at yy");
       
       transaction t (db->begin ());

       // Make objects persistent and save their ids for later use.
       relation_id = db->persist (john);
    
       t.commit ();
     }

     // Show a selection of the persisted data
     
     typedef odb::query<relation> query;
     typedef odb::result<relation> result;

     // Show action

     {
       transaction t (db->begin ());
       
       unsigned int minid;
       
       result r (db->query<relation> (query::id > 10));


       for (result::iterator i (r.begin ()); i != r.end; ++i)
       {
         cout << "Relation: , " << i->get_first() << "!" << endl;
       }

       t.commit ();
      }
     
   }
   catch (const odb::exception& e)
   {
      cerr << e.what () << endl;
      return 1;
   }
}




Then i get an error:


main.cpp: In function ‘int main(int, char**)’:
main.cpp:54:48: error: no match for ‘operator!=’ (operand types are
‘odb::result<relation>::iterator {aka odb::result_iterator<relation,
(odb::class_kind)0u>}’ and ‘<unresolved overloaded function type>’)
        for (result::iterator i (r.begin ()); i != r.end; ++i)
                                                ^
main.cpp:54:48: note: candidates are:
In file included from /usr/include/c++/4.8.3/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/4.8.3/vector:60,
                 from main.cpp:2:
/usr/include/c++/4.8.3/bits/stl_pair.h:227:5: note: template<class _T1,
class _T2> bool std::operator!=(const std::pair<_T1, _T2>&, const
std::pair<_T1, _T2>&)
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)

What can be the cause of this?




More information about the odb-users mailing list