0

I write too simple odb example and copy all codes from document but when calling db.persist(john) compiler say

/usr/include/odb/traits.hxx: In instantiation of ‘struct odb::object_traits_impl’: /usr/include/odb/database.txx:61:28: required from ‘typename odb::object_traits::id_type odb::database::persist_(const typename odb::object_traits::pointer_type&) [with T = Person; odb::database_id DB = (odb::database_id)1; typename odb::object_traits::id_type = odb::access::object_traits::id_type; typename odb::object_traits::pointer_type = Person*]’ /usr/include/odb/sqlite/database.ixx:47:37: required from ‘typename odb::object_traits::id_type odb::sqlite::database::persist(T*) [with T = Person; typename odb::object_traits::id_type = odb::access::object_traits::id_type]’ /home/mohsen/Desktop/Workstation/Projects/C++/Rubik/main.cpp:25:21: required from here /usr/include/odb/traits.hxx:177:10: error: invalid use of incomplete type ‘class odb::access::object_traits_impl’ struct object_traits_impl:

what is wrong ?

my codes:

main.cpp

using namespace std;
using namespace odb::core;

int main(int argc, char **argv) {

odb::sqlite::database db("sqlite.db", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);

    Person john("John", "Doe", 33);
//    Person jane("Jane", "Doe", 32);
//    Person joe("Joe", "Dirt", 30);

//    odb::transaction t(db.begin());
    db.persist(john);
//    t.commit();

    return 0;
}

Person.h

#pragma db object
class Person
{
public:
    Person (const std::string& first,
            const std::string& last,
            unsigned short age)
            : first_ (first), last_ (last), age_ (age)
    {
    }

    const std::string&
    first () const
    {
        return first_;
    }

    const std::string&
    last () const
    {
        return last_;
    }

    unsigned short
    age () const
    {
        return age_;
    }

    void
    age (unsigned short age)
    {
        age_ = age;
    }

private:
    friend class odb::access;

    Person () {}

#pragma db id auto
    unsigned long id_;

    std::string first_;
    std::string last_;
    unsigned short age_;
};

odb compile command

odb -dsqlite --generate-query --generate-session --generate-schema --generate-prepared --output -dir/home/mohsen/Desktop/Workstation/Projects/C++/Rubik/cmake-build-debug/odb_gen --hxx-suffix.h --ixx-suffix_inline.h --cxx-suffix.cpp --odb-file-suffix_odbPerson.h
4

1 回答 1

0
于 2017-10-27T13:57:59.140 回答