在哪里声明BOOST_CLASS_EXPORT进行序列化 [英] Where to declare BOOST_CLASS_EXPORT for serialization
问题描述
我要序列化数据,并且具有多态类.
I want to serialize my data and i have polymorphic classes .
最初,当我学习序列化的过程时,我在其头文件中声明了Inherited类.
Initially when i was learning the process of the Serialization i declared the Inherited class in their header files.
Header file for Sphere which is sub class of geometry
BOOST_CLASS_EXPORT(Sphere)
但是当我尝试在我的项目中执行操作时,出现链接器错误2005,指出该对象已在对象中定义.
but when i tried doing in my project i got the linker error2005 stating that the object is already defined in the object.
因此,我尝试在cpp文件中声明BOOST_CLASS_EXPORT(Sphere),但随后我得到了未注册或导出错误消息的派生类.
So i tried declaring the BOOST_CLASS_EXPORT(Sphere) in the cpp file but than i got error message derived class not registered or exported.
最终,我通过在Main文件中声明派生类使它起作用.
Eventually i got it working by declaring the derived class in the Main file.
BOOST_CLASS_EXPORT_GUID(Sphere, "Sphere");
但是这里的问题是,如果我有30个对象,则需要在主文件中声明它们;如果我添加任何新类,则需要再次在主文件中声明它们.
But the problem here is that if i have 30 objects i will need to declare them in the main file and if i add any new classes than again i need to declare them in main file.
我可以在其类的标头或cpp文件中定义导出.
Can i define the export in their header or cpp files of the class.
推荐答案
您要分隔导出KEY和IMPLEMENTATION.
You want to separate the export KEY and IMPLEMENTATION.
我有一些非常完整的答案,其中一些还涉及多态性和抽象基础.看到那里有很好的建议:
I have some very complete answers up, some of which also touch on polymorphism and abstract bases. See there for good suggestions:
- 最简单的介绍 Boost序列化-导出多个CPP文件(没有代码,但也许最具解释性)
- 一个完整的示例,其中包含更多解释和文档引文,使用多个翻译单元: BOOST_CLASS_EXPORT_ *宏不是像register_type()一样工作(完成了几个源文件和makefile)
- 另一个具有多个翻译单元的示例 boost的序列化嵌套结构不起作用
- 混合静态多态和动态多态的微妙陷阱:序列化多态界面
- 为什么提升::尽管看起来一切正常,序列化还是不起作用? (未注册的课程")
- 火箭科学黑客:对衍生类进行Boost序列化与私人成员
- The simplest introduction Boost Serialization - Exporting in multiple CPP files (no code, but perhaps most explanatory)
- A complete example with more explanation and documentation quotes, in multiple translation units: Boost serialization, loading an archived class by base type gives wrong data
- BOOST_CLASS_EXPORT_* macros are not working like register_type() (complete with several source files and makefile)
- Another sample with multiple translation units boost serialization of nested struct does not work
- A subtle pitfall mixing static polymorphism and dynamic polymorphism: Serialize Polymorph Interface
- Why does boost::serialize not work despite everything seeming right? ("unregistered class")
- Rocket science hacks: Boost serialization of derived class with private members
这篇关于在哪里声明BOOST_CLASS_EXPORT进行序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!