如果我重命名类名,Boost 序列化会中断吗?

问题描述 投票:0回答:1

我正在开发一个具有有效序列化逻辑的项目。我已使用 Visual Assist 重命名了类名称。这会打破现在的逻辑吗?我需要任何版本控制来处理这个问题吗?

我尝试查看文档,但没有任何关于此案例的内容。

boost boost-serialization
1个回答
0
投票

这要看情况。

如果您输入信息,它只会影响序列化。反过来,只有当您具有多态基类(并将它们序列化)时才需要:https://www.boost.org/doc/libs/1_84_0/libs/serialization/doc/tutorial.html#drivenclasses

您将通过导出的类认识到这一点:https://www.boost.org/doc/libs/1_84_0/libs/serialization/doc/special.html#export

在这种情况下,您应该使用命名的导出宏:

需要某种可用于选择的标识符 加载对象时要调用的代码。标准 C++ 确实如此 实现 typeid() ,它可用于返回唯一的字符串 班级。这对于我们的目的来说并不完全令人满意 原因如下:

There is no guarantee that the string is the same across platforms. This would then fail to support portable archives.
In using code modules from various sources, classes may have to be wrapped in different namespaces in different programs.
There might be classes locally defined in different code modules that have the same name.
There might be classes with different names that we want to consider equivalent for purposes of serialization. 

因此在序列化库中,这是通过调用来解决的

BOOST_CLASS_EXPORT_KEY2(my_class, "my_class_external_identifier")
于 声明类的头文件。在绝大多数 应用程序中,类名对于外部应用程序来说效果很好 标识符字符串,因此定义了以下快捷方式 -
BOOST_CLASS_EXPORT_KEY(my_class)

© www.soinside.com 2019 - 2024. All rights reserved.