[odb-users] Can I use relationship and polymorphic at the same time?

Jerry kexuetutu at sina.com
Mon Nov 12 04:18:18 EST 2018


Hello ODB
I'm trying use ODB in my program to save a class A that contains a std::map, which value is a pointer to base class B. My code is some what like below:there are 2 *.h to define each class/*----------File1----------*/
#pragma db object polymorphicclass B{......}
#pragma db object no_idclass B1 : B{......}
/*----------File2----------*/
#pragma db objectclass A{......protected:	std::map<unsigned long, std::shared_ptr<B>> m_CheckSectionResultTable;......}
When I compile the File2 with ODB, it tells me this
D:\v1_8_1-New\src\YJKBridge\BridgePostProcess\BridgePostProcess\ElementDesignResult.h:40:68: error: unable to map C++ type '::std::map< long unsigned int, ::std::shared_ptr< ::SectionDesignResultBase > >::mapped_type' used in data member 'm_CheckSectionResultTable' to a SQLite database type

My question are: 1.How to solve this error?Class B is already defined "object abstract", why can't Class A recognise the "std::map<unsigned long, std::shared_ptr<B>>" type in ODB compiler?
2.I'm confuse with the "value" and "object", this are my point:(1).I'll use "value" if one class is another class's member (direct, not by pointer);(2).I'll use "object" if i want to use the features of abstract and polymorphic;Question2: if a class need polymorphic and this class is another class's member(need "value" feature), how to define the ODB type?
3、I'm confuse with the "abstract" useage, this are my point:(1).I'll use "abstract" if i want to save class which contains base class's memeber; (I'm not sure if this is right. I have tried save Class B, which inherit Class A without the "abstract" lable, it seems the Class B can also save members which defined in Class A)(2).I'll use "polymorphic" if i want to save class by it's base class pointer;Question3: In program, class is common use both inherit and polymorphic. For this class, how can i define it's ODB type? (The manual tell me an object can't be both "abstract" and "polymorphic".)
PS:I use VS2013 windowns
Thinks
-------------- next part --------------
A non-text attachment was scrubbed...
Name: =?GBK?B?Q1N0cmluZy10cmFpdHMuemlw?=
Type: application/zip
Size: 4693 bytes
Desc: not available
Url : https://codesynthesis.com/pipermail/odb-users/attachments/20181112/b6dad9f6/GBKBQ1N0cmluZy10cmFpdHMuemlw.zip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: =?GBK?B?MS5o?=
Type: application/octet-stream
Size: 590 bytes
Desc: not available
Url : https://codesynthesis.com/pipermail/odb-users/attachments/20181112/b6dad9f6/GBKBMS5o.obj


More information about the odb-users mailing list