[odb-users] Simple Raw Pointer Container
Sachin Kumar
sachnk at gmail.com
Thu Feb 27 16:20:47 EST 2014
Greetings,
I'm relatively new to ODB, so there likely is a simple solution to my
problem. As outlined in the sample below, I have two classes: MyHolder and
MyElement. MyHolder has a std::vector of MyElement.
The code below works and I get the appropriate tables in my database,
namely myholder and myholder_myelement. However, if I change the
std::vector to be a vector of MyElement pointers, it doesn't work. I get a
"error: unable to map C++ type" error from the ODB compiler.
I've tried several things to fix this:
1. Use #pragma db object instead of #pragma db value for MyElement. This
seems fix the ODB compile problem, except that the myholder_myelement table
now contains the actual pointer value, which isn't at all useful. Is this
expected?
2. I've also tried using boost::shared_ptr, thinking that perhaps using raw
pointers causes problems, but to no avail.
What's the right way to do this?
class MyElement;
#pragma db object
#pragma db model version(1, 1, open)
class MyHolder
{
...
private:
friend class odb::access;
// some members
std::vector<MyElement> elements;
};
#pragma db value
class MyElement
{
...
private:
friend class odb::acess;
// some members
};
More information about the odb-users
mailing list