[odb-users] Persisting class instantiated from a template

Balázs Bayer balazs.bayer at gmail.com
Wed Mar 15 08:32:45 EDT 2017


Hi all,

I would like to persist a class instantiated from a template into an SQLite
database using ODB. Lets say I have the following class in a header called
*result.hpp*:

template <typename valuetype, int size>class Result {
  public:
    valuetype getValue(int i) const { return Values[i]; };
    int getId() const { return Id; };
    void setValue(valuetype _value, int i) { Values[i] = _value; }
    void setId(int _Id) { Id = _Id; }

  private:
    int Id;
    std::array<valuetype, size> Values;};


and I have another header file called *result-mapping.hpp* with the
following content:

#include "result.hpp"
typedef Result<float, 7> ResultFloatSeven;
#pragma db value(ResultFloatSeven) definition transient#pragma db
member(ResultFloatSeven::getId) virtual(int) access(getId) <-- line
11#pragma db member(ResultFloatSeven::getValue) virtual(float)
access(getValue)

When I try to generate the database support code with the command

odb --std c++11 -d sqlite --odb-prologue "#include \"result-mapping.hpp\""
--generate-query result.hpp

I get the following error:

result-mapping.hpp:11:57: error: unable to find suitable modifier function
'getId'

What is wrong here?

Thanks!
Balázs

Btw I laready posted this question on stackoverflow, but did not get any
feedback until now.

http://stackoverflow.com/questions/42684473/c-odb-persisting-class-instantiated-from-a-template


More information about the odb-users mailing list