我正在使用非常简单的业务logi开发程序,有链接到github:https://github.com/Anakinud/OOPStudiesProject.git。
问题是,我想序列化所有三个管理器的状态,每个管理器都使用通用存储库(替代SQL数据库)。当我想序列化数据i PaymentManager:void PaymentManager::SaveState() {
_paymentRepo->SaveRepo("Payments.txt");
}
付款有shared_ptr和shared_ptr,序列化如下:
template <class Archive>
void Payment::serialize(Archive &ar, const unsigned int version) {
// serialize the data members of Person class
ar & _id; //string
ar & _sender; //shared_ptr<Client>
ar & _recipient; //shared_ptr<Nanny>
ar & _paymentDate; //boost:gregorian::date;
ar & _amount; //int
}
序列化仅适用于ClientManager,seialization代码Client :: serialize:
template <class Archive>
void Client::serialize(Archive &ar, const unsigned int version) {
// serialize the data members of Person class
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Person);
ar & _address & _employedNanny;
}
和Nanny序列化:
template <class Archive>
void Nanny::serialize(Archive &ar, const unsigned int version) {
// serialize the data members of Person class
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Person);
ar & _client;
ar & _nannyType;
ar & _startDate;
}
在存储库中形式化序列化:
template<class Archive>
void serialize(Archive &ar, const unsigned int version) {
ar.template register_type<T>();
ar & _objectsList;
}
我在测试中调用PaymentManager :: SaveState,当序列化使用info:
抛出异常时致命错误:在“PaymentManagerTesting / SaveData”中:boost :: archive :: archive_exception:未注册的类 - 未注册或导出的派生类
当NannyManager因
而失败时致命错误:在“NannyTesting / SaveData”中:内存访问违规 地址:0x00000049:故障地址没有映射 /home/pobi/elo/Niania/biblioteka/test/NannyManagerTest.cpp(89):last checkpoint:“SaveData”条目。
我不知道为什么它适用于CLientManager但不适用于PaymentManager或NannyManager。