ODB无效使用不完整类型'class odb :: access :: object_traits_impl <person,(odb :: database_id)1 =“”>'

时间:2017-08-10 11:34:25

标签: c++ sqlite incomplete-type odb

我写了太简单的odb示例并从文档中复制了所有代码但是在调用db.persist(john)编译时说

  

/usr/include/odb/traits.hxx:在'struct odb :: object_traits_impl'的实例化中:   /usr/include/odb/database.txx:61:28:需要'typename odb :: object_traits :: id_type odb :: database :: persist_(const typename odb :: object_traits :: pointer_type&amp;)[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:需要'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:从这里要求   /usr/include/odb/traits.hxx:177:10:错误:无效使用不完整类型'class odb :: access :: object_traits_impl'      struct object_traits_impl:

出了什么问题?

我的代码:

的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编译命令

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

1 个答案:

答案 0 :(得分:0)

您收到此错误是因为‘class odb::access::object_traits_impl<Person, (odb::database_id)1>’在odb生成的文件Person-odb.hxx中定义。

在main.cpp文件的开头包含"Person-odb.hxx"可以解决您的问题。