我正在使用C boost库1.6.3来序列化并保存到文本文件中,其中包含不同类的游戏的主类是指针和参考类型变量,问题是当我加载文件时,它会崩溃给出此输出:
Assertion failed: register_type(bpis_ptr->get_basic_serializer()) == cid, file libsserializationsrcbasic_iarchive.cpp, line 454
问题是,此类类似于其他类别的序列化,并且没有错误。
按照BOOST ::序列化说明序列化是我正在做的事情:1)在基础类中:添加朋友类以串行访问,以及序列化的函数,例如:
class BJShoe
{
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int file_version)
{
ar & BOOST_SERIALIZATION_NVP(totalCards);
ar & BOOST_SERIALIZATION_NVP(cards);
ar & BOOST_SERIALIZATION_NVP(numCards);
}
protected:
int totalCards[10],
cards[10],
numCards;
}
所以,对于主类,我有类似的东西:
class Game {
int numDecks;
bool hitSoft17;
bool doubleAnyTotal;
bool double9;
bool doubleSoft;
bool doubleAfterHit;
bool doubleAfterSplit;
bool resplit;
bool resplitAces;
bool lateSurrender;
int dealerSpeed;
BJStrategy maxValueStrategy;
Progress progress;
// Release all objects on exit
BJRules *rules;
Player *strategy;
Hand *dealer;
Probabilities *dealerProbabilities;
Shoe *shoe;
BJShoe *distribution;
PlayerHand *tempHand;
//counters and game-loop vars
int lastWager;
int balance;
Card tempCard;
PlayerHand playerHands[4];
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar.template register_type<BJShoe*>();
ar.template register_type<PlayerHand*>();
//etc.
ar.template register_type<BJShoe>();
ar.template register_type<PlayerHand>();
cout << "numDecksn";
ar & BOOST_SERIALIZATION_NVP(numDecks);
cout << "hitSoft17n";
ar & BOOST_SERIALIZATION_NVP(hitSoft17);
cout << "doubleAnyTotaln";
ar & BOOST_SERIALIZATION_NVP(doubleAnyTotal);
cout << "double9n";
ar & BOOST_SERIALIZATION_NVP(double9);
cout << "doubleSoftn";
ar & BOOST_SERIALIZATION_NVP(doubleSoft);
cout << "doubleAfterHitn";
ar & BOOST_SERIALIZATION_NVP(doubleAfterHit);
cout << "doubleAfterSplitn";
ar & BOOST_SERIALIZATION_NVP(doubleAfterSplit);
cout << "resplitn";
ar & BOOST_SERIALIZATION_NVP(resplit);
cout << "resplitAcesn";
ar & BOOST_SERIALIZATION_NVP(resplitAces);
cout << "lateSurrendern";
ar & BOOST_SERIALIZATION_NVP(lateSurrender);
cout << "dealerSpeedn";
ar & BOOST_SERIALIZATION_NVP(dealerSpeed);
cout << "maxValueStrategyn";
ar & BOOST_SERIALIZATION_NVP(maxValueStrategy);
cout << "progressn";
ar & BOOST_SERIALIZATION_NVP(progress);
cout << "rulesn";
ar & BOOST_SERIALIZATION_NVP(rules);
cout << "strategyn";
ar & BOOST_SERIALIZATION_NVP(strategy);
cout << "dealern";
ar & BOOST_SERIALIZATION_NVP(dealer);
cout << "dealerProbabilitiesn";
ar & BOOST_SERIALIZATION_NVP(dealerProbabilities);
cout << "shoen";
ar & BOOST_SERIALIZATION_NVP(shoe);
cout << "distributionn";
ar & BOOST_SERIALIZATION_NVP(distribution);
cout << "tempHandn";
ar & BOOST_SERIALIZATION_NVP(tempHand);
cout << "lastWagern";
ar & BOOST_SERIALIZATION_NVP(lastWager);
cout << "balancen";
ar & BOOST_SERIALIZATION_NVP(balance);
cout << "tempCardn";
ar & BOOST_SERIALIZATION_NVP(tempCard);
/*for (int i = 0; i < 4; i++) {
ar & BOOST_SERIALIZATION_NVP(playerHands[i]);
cout << "playerHands["<<i<<"]n";
}*/
ar & BOOST_SERIALIZATION_NVP(playerHands);
cout << "playerHandsn";
}
}
2)在儿童课中,执行与(1)相同并添加base_object函数,从bjshoe继承的鞋子的示例:
boost::serialization::base_object<BJShoe>(*this);
3)导出CPP中的类,例如:
BOOST_CLASS_EXPORT(Shoe)
BOOST_CLASS_EXPORT(BJShoe)
4)函数保存
void Game::save(const char* filename)
{
ofstream ofs(filename);
if (!ofs.good()) return;
text_oarchive oa(ofs);
//register all the classes, example:
oa.register_type<Shoe>();
oa.register_type<BJShoe>();
oa.register_type<Game>();
oa << boost::serialization::make_nvp("game",instance);
ofs.close();
}
5)加载功能:
void Game::load(const char* filename)
{
ifstream ifs(filename);
if (!ifs.good()) return;
text_iarchive ia(ifs);
//register all the classes, example:
ia.register_type<Shoe>();
ia.register_type<BJShoe>();
ia.register_type<Game>();
ia >> boost::serialization::make_nvp("game",instance);
ifs.close();
}
6)调用保存(" play.data");加载(" play.data");将程序带到崩溃,这是日志:
./bj play
numDecks
hitSoft17
doubleAnyTotal
double9
doubleSoft
doubleAfterHit
doubleAfterSplit
resplit
resplitAces
lateSurrender
dealerSpeed
maxValueStrategy
progress
rules
strategy
dealer
dealerProbabilities
shoe
distribution
Segmentation fault
[jbelon@localhost cpp]$ gdb ./bj
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /var/www/html/blackjack/cpp/bj...done.
(gdb) run play
Starting program: /var/www/html/blackjack/cpp/./bj play
numDecks
hitSoft17
doubleAnyTotal
double9
doubleSoft
doubleAfterHit
doubleAfterSplit
resplit
resplitAces
lateSurrender
dealerSpeed
maxValueStrategy
progress
rules
strategy
dealer
dealerProbabilities
shoe
distribution
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7bad05c in boost::archive::detail::basic_iarchive_impl::load_preamble (this=0x6bd4c0, ar=..., co=...) at libs/serialization/src/basic_iarchive.cpp:319
319 if(co.bis_ptr->class_info()){
(gdb) backtrace
#0 0x00007ffff7bad05c in boost::archive::detail::basic_iarchive_impl::load_preamble (this=0x6bd4c0, ar=..., co=...) at libs/serialization/src/basic_iarchive.cpp:319
#1 0x00007ffff7bae132 in boost::archive::detail::basic_iarchive_impl::load_pointer (this=0x6bd4c0, ar=..., t=@0x6bdcb8: 0x6bd790,
bpis_ptr=0x6b7190 <boost::serialization::singleton<boost::archive::detail::pointer_iserializer<boost::archive::text_iarchive, BJShoe> >::get_instance()::t>, finder=<optimized out>)
at libs/serialization/src/basic_iarchive.cpp:446
#2 0x0000000000457063 in boost::archive::detail::load_pointer_type<boost::archive::text_iarchive>::invoke<BJShoe*> (ar=..., t=@0x6bdcb8: 0x6bd790)
at /usr/include/boost/archive/detail/iserializer.hpp:524
#3 0x0000000000456484 in boost::archive::load<boost::archive::text_iarchive, BJShoe*> (ar=..., t=@0x6bdcb8: 0x6bd790) at /usr/include/boost/archive/detail/iserializer.hpp:592
#4 0x000000000045609e in boost::archive::detail::common_iarchive<boost::archive::text_iarchive>::load_override<BJShoe*> (this=0x7fffffffdb80, t=@0x6bdcb8: 0x6bd790)
at /usr/include/boost/archive/detail/common_iarchive.hpp:66
#5 0x0000000000455bab in boost::archive::basic_text_iarchive<boost::archive::text_iarchive>::load_override<BJShoe*> (this=0x7fffffffdb80, t=@0x6bdcb8: 0x6bd790)
at /usr/include/boost/archive/basic_text_iarchive.hpp:65
#6 0x00000000004558ff in boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::load_override<BJShoe*> (this=0x7fffffffdb80, t=@0x6bdcb8: 0x6bd790)
at /usr/include/boost/archive/text_iarchive.hpp:82
#7 0x00000000004555c0 in boost::archive::detail::interface_iarchive<boost::archive::text_iarchive>::operator>><BJShoe*> (this=0x7fffffffdb80, t=@0x6bdcb8: 0x6bd790)
at /usr/include/boost/archive/detail/interface_iarchive.hpp:60
#8 0x0000000000455209 in boost::serialization::nvp<BJShoe*>::load<boost::archive::text_iarchive> (this=0x7fffffffd000, ar=...) at /usr/include/boost/serialization/nvp.hpp:87
#9 0x0000000000454d72 in boost::serialization::access::member_load<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:101
#10 0x0000000000454889 in boost::serialization::detail::member_loader<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> >::invoke (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/split_member.hpp:54
#11 0x0000000000454345 in boost::serialization::split_member<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/split_member.hpp:69
#12 0x0000000000453ce5 in boost::serialization::nvp<BJShoe*>::serialize<boost::archive::text_iarchive> (this=0x7fffffffd000, ar=..., file_version=0)
at /usr/include/boost/serialization/nvp.hpp:89
#13 0x00000000004536c2 in boost::serialization::access::serialize<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:118
#14 0x00000000004530dc in boost::serialization::serialize<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#15 0x0000000000452a49 in boost::serialization::serialize_adl<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#16 0x00000000004522b1 in boost::archive::detail::load_non_pointer_type<boost::archive::text_iarchive>::load_only::invoke<boost::serialization::nvp<BJShoe*> > (ar=..., t=...)
at /usr/include/boost/archive/detail/iserializer.hpp:373
#17 0x0000000000451a32 in boost::archive::detail::load_non_pointer_type<boost::archive::text_iarchive>::invoke<boost::serialization::nvp<BJShoe*> const> (ar=..., t=...)
at /usr/include/boost/archive/detail/iserializer.hpp:439
#18 0x000000000045111f in boost::archive::load<boost::archive::text_iarchive, boost::serialization::nvp<BJShoe*> const> (ar=..., t=...)
at /usr/include/boost/archive/detail/iserializer.hpp:592
#19 0x000000000045099e in boost::archive::detail::common_iarchive<boost::archive::text_iarchive>::load_override<boost::serialization::nvp<BJShoe*> const> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/detail/common_iarchive.hpp:66
#20 0x00000000004503d5 in boost::archive::basic_text_iarchive<boost::archive::text_iarchive>::load_override<boost::serialization::nvp<BJShoe*> const> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/basic_text_iarchive.hpp:65
#21 0x000000000044fdab in boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::load_override<boost::serialization::nvp<BJShoe*> const> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/text_iarchive.hpp:82
#22 0x000000000044f6f0 in boost::archive::detail::interface_iarchive<boost::archive::text_iarchive>::operator>><boost::serialization::nvp<BJShoe*> const> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/detail/interface_iarchive.hpp:60
#23 0x000000000044e2d3 in boost::archive::detail::interface_iarchive<boost::archive::text_iarchive>::operator&<boost::serialization::nvp<BJShoe*> const> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/detail/interface_iarchive.hpp:67
#24 0x000000000044cc31 in Game::serialize<boost::archive::text_iarchive> (this=0x6bdc60, ar=..., version=1) at Game.h:271
#25 0x000000000044aeee in boost::serialization::access::serialize<boost::archive::text_iarchive, Game> (ar=..., t=..., file_version=1) at /usr/include/boost/serialization/access.hpp:118
#26 0x0000000000449f6b in boost::serialization::serialize<boost::archive::text_iarchive, Game> (ar=..., t=..., file_version=1) at /usr/include/boost/serialization/serialization.hpp:69
#27 0x0000000000447364 in boost::serialization::serialize_adl<boost::archive::text_iarchive, Game> (ar=..., t=..., file_version=1) at /usr/include/boost/serialization/serialization.hpp:128
#28 0x0000000000444677 in boost::archive::detail::iserializer<boost::archive::text_iarchive, Game>::load_object_data (
this=0x6b8090 <boost::serialization::singleton<boost::archive::detail::iserializer<boost::archive::text_iarchive, Game> >::get_instance()::t>, ar=..., x=0x6bdc60, file_version=1)
at /usr/include/boost/archive/detail/iserializer.hpp:188
#29 0x00007ffff7bad852 in load_object (bis=..., t=0x6bdc60, ar=..., this=0x6bd4c0) at libs/serialization/src/basic_iarchive.cpp:362
#30 boost::archive::detail::basic_iarchive::load_object (this=0x7fffffffdb80, t=<optimized out>, bis=...) at libs/serialization/src/basic_iarchive.cpp:537
#31 0x0000000000454e03 in boost::archive::detail::load_non_pointer_type<boost::archive::text_iarchive>::load_standard::invoke<Game> (ar=..., t=...)
at /usr/include/boost/archive/detail/iserializer.hpp:387
#32 0x0000000000454914 in boost::archive::detail::load_non_pointer_type<boost::archive::text_iarchive>::invoke<Game> (ar=..., t=...) at /usr/include/boost/archive/detail/iserializer.hpp:439
#33 0x00000000004543c5 in boost::archive::load<boost::archive::text_iarchive, Game> (ar=..., t=...) at /usr/include/boost/archive/detail/iserializer.hpp:592
#34 0x0000000000453d6e in boost::archive::detail::common_iarchive<boost::archive::text_iarchive>::load_override<Game> (this=0x7fffffffdb80, t=...)
at /usr/include/boost/archive/detail/common_iarchive.hpp:66
#35 0x0000000000453745 in boost::archive::basic_text_iarchive<boost::archive::text_iarchive>::load_override<Game> (this=0x7fffffffdb80, t=...)
我不明白这是否与构造函数或序列化函数有关,因为看起来它试图用null初始化,对吗?
我必须重写游戏代码,并且我添加了所有复制构造函数;现在运行正常,加载并保存数据。问题是信息的顺序和构造函数的使用。但是,有时它会用玩家指针崩溃,我必须检查一下。现在的另一个问题是,它仅适用于Windows,当时将数据保存在GNU/Linux中,这是新的分割故障崩溃日志:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004215f6 in boost::archive::basic_text_oprimitive<std::ostream>::save<int > (this=0x7fffffffdeb8, t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/basic_text_oprimitive.hpp:92
92 os << t;
(gdb) reverse-step
Target child does not support this command.
(gdb) reverse-continue
Target child does not support this command.
(gdb) backtrace
#0 0x00000000004215f6 in boost::archive::basic_text_oprimitive<std::ostream>::save <int> (this=0x7fffffffdeb8, t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/basic_text_oprimitive.hpp:92
#1 0x000000000041e9c5 in boost::archive::text_oarchive_impl<boost::archive::text_o archive>::save<int> (this=0x7fffffffdea0, t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/text_oarchive.hpp:61
#2 0x000000000041cf10 in boost::archive::save_access::save_primitive<boost::archiv e::text_oarchive, int> (ar=..., t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/oserializer.hpp:88
#3 0x000000000041a989 in boost::archive::detail::save_non_pointer_type<boost::arch ive::text_oarchive>::save_primitive::invoke<int> (ar=...,
t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/oserializer.hpp:232
#4 0x000000000041876c in boost::archive::detail::save_non_pointer_type<boost::arch ive::text_oarchive>::invoke<int> (ar=..., t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#5 0x00000000004265ca in boost::archive::save<boost::archive::text_oarchive, int c onst> (ar=..., t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#6 0x0000000000425fa8 in boost::archive::detail::common_oarchive<boost::archive::t ext_oarchive>::save_override<int const> (this=0x7fffffffdea0,
t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#7 0x0000000000425991 in boost::archive::basic_text_oarchive<boost::archive::text_ oarchive>::save_override<int const> (this=0x7fffffffdea0,
t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#8 0x00000000004251da in boost::archive::detail::interface_oarchive<boost::archive ::text_oarchive>::operator<< <int const> (this=0x7fffffffdea0,
t=@0xffffe3d0: <error reading variable>)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#9 0x0000000000430ecf in boost::serialization::nvp<int const>::save<boost::archive ::text_oarchive> (this=0x7fffffffc400, ar=...)
at /usr/include/boost/serialization/nvp.hpp:79
#10 0x0000000000430a3f in boost::serialization::access::member_save<boost::archive: :text_oarchive, boost::serialization::nvp<int const> const> (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/access.hpp:93
#11 0x000000000043070c in boost::serialization::detail::member_saver<boost::archive ::text_oarchive, boost::serialization::nvp<int const> >::invoke (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/split_member.hpp:43
#12 0x00000000004303ac in boost::serialization::split_member<boost::archive::text_o archive, boost::serialization::nvp<int const> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/split_member.hpp:69
#13 0x000000000042feef in boost::serialization::nvp<int const>::serialize<boost::ar chive::text_oarchive> (this=0x7fffffffc400, ar=..., file_version=0)
at /usr/include/boost/serialization/nvp.hpp:89
#14 0x000000000042fb93 in boost::serialization::access::serialize<boost::archive::t ext_oarchive, boost::serialization::nvp<int const> > (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/access.hpp:118
#15 0x000000000042f87d in boost::serialization::serialize<boost::archive::text_oarc hive, boost::serialization::nvp<int const> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#16 0x000000000042f610 in boost::serialization::serialize_adl<boost::archive::text_ oarchive, boost::serialization::nvp<int const> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#17 0x000000000042f3cb in boost::archive::detail::save_non_pointer_type<boost::arch ive::text_oarchive>::save_only::invoke<boost::serialization::nvp<int const> > (
ar=..., t=...) at /usr/include/boost/archive/detail/oserializer.hpp:241
#18 0x000000000042f1a2 in boost::archive::detail::save_non_pointer_type<boost::arch ive::text_oarchive>::invoke<boost::serialization::nvp<int const> > (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#19 0x000000000042ee56 in boost::archive::save<boost::archive::text_oarchive, boost ::serialization::nvp<int const> const> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#20 0x000000000042ebbc in boost::archive::detail::common_oarchive<boost::archive::t ext_oarchive>::save_override<boost::serialization::nvp<int const> const> (
---Type <return> to continue, or q <return> to quit---
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#21 0x000000000042e943 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::nvp<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#22 0x000000000042e59a in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <boost::serialization::nvp<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#23 0x000000000042e13f in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<boost::serialization::nvp<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:71
#24 0x000000000042d9d4 in boost::serialization::array<int const>::serialize_optimized<boost::archive::text_oarchive> (this=0x7fffffffc620, ar=...)
at /usr/include/boost/serialization/array.hpp:72
#25 0x000000000042d1a9 in boost::serialization::array<int const>::serialize<boost::archive::text_oarchive> (this=0x7fffffffc620, ar=..., version=0)
at /usr/include/boost/serialization/array.hpp:104
#26 0x000000000042c8f2 in boost::serialization::access::serialize<boost::archive::text_oarchive, boost::serialization::array<int const> > (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/access.hpp:118
#27 0x000000000042c346 in boost::serialization::serialize<boost::archive::text_oarchive, boost::serialization::array<int const> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#28 0x000000000042be09 in boost::serialization::serialize_adl<boost::archive::text_oarchive, boost::serialization::array<int const> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#29 0x000000000042b861 in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_only::invoke<boost::serialization::array<int const> > (
ar=..., t=...) at /usr/include/boost/archive/detail/oserializer.hpp:241
#30 0x000000000042b46e in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::invoke<boost::serialization::array<int const> > (ar=...,
t=...) at /usr/include/boost/archive/detail/oserializer.hpp:308
#31 0x000000000042a840 in boost::archive::save<boost::archive::text_oarchive, boost::serialization::array<int const> const> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#32 0x000000000042a02e in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::array<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#33 0x000000000042970d in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::array<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#34 0x0000000000428a92 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <boost::serialization::array<int const> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#35 0x0000000000428071 in boost::archive::detail::save_array_type<boost::archive::text_oarchive>::invoke<int [11]> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:503
#36 0x00000000004278c1 in boost::archive::save<boost::archive::text_oarchive, int const [11]> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#37 0x000000000042729c in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<int const [11]> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#38 0x0000000000426d11 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<int const [11]> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#39 0x00000000004266aa in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <int const [11]> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#40 0x0000000000426081 in boost::archive::detail::interface_oarchive<boost::archive---Type <return> to continue, or q <return> to quit---
::text_oarchive>::operator&<int [11]> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:71
#41 0x000000000042a15a in BJHand::serialize<boost::archive::text_oarchive> (
this=0xffffe3d0, ar=..., version=0) at src/blackjack.h:31
#42 0x00000000004297b9 in boost::serialization::access::serialize<boost::archive::text_oarchive, BJHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:118
#43 0x0000000000428c2f in boost::serialization::serialize<boost::archive::text_oarchive, BJHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#44 0x0000000000428229 in boost::serialization::serialize_adl<boost::archive::text_oarchive, BJHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#45 0x00000000004279da in boost::archive::detail::oserializer<boost::archive::text_oarchive, BJHand>::save_object_data (
this=0x6f9670 <boost::serialization::singleton<boost::archive::detail::oserializer<boost::archive::text_oarchive, BJHand> >::get_instance()::t>, ar=...,
x=0xffffe3d0) at /usr/include/boost/archive/detail/oserializer.hpp:148
#46 0x00007ffff7bae94d in save_object (bos=..., t=0xffffe3d0, ar=...,
this=0x6fe570) at libs/serialization/src/basic_oarchive.cpp:292
#47 boost::archive::detail::basic_oarchive::save_object (this=0x7fffffffdea0,
x=0xffffe3d0, bos=...) at libs/serialization/src/basic_oarchive.cpp:423
#48 0x0000000000427359 in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<BJHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:253
#49 0x0000000000426dbd in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::invoke<BJHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#50 0x000000000042675c in boost::archive::save<boost::archive::text_oarchive, BJHand const> (ar=..., t=...) at /usr/include/boost/archive/detail/oserializer.hpp:525
#51 0x0000000000426134 in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<BJHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#52 0x0000000000425b1b in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<BJHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#53 0x0000000000425338 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <BJHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#54 0x0000000000424b81 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<BJHand> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:71
#55 0x00000000004240d9 in Hand::serialize<boost::archive::text_oarchive> (
this=0xffffe3d0, ar=..., version=0) at src/game.cpp:300
#56 0x0000000000423723 in boost::serialization::access::serialize<boost::archive::text_oarchive, Hand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:118
#57 0x0000000000422047 in boost::serialization::serialize<boost::archive::text_oarchive, Hand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#58 0x000000000041f19f in boost::serialization::serialize_adl<boost::archive::text_oarchive, Hand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#59 0x000000000041d478 in boost::archive::detail::oserializer<boost::archive::text_oarchive, Hand>::save_object_data (
this=0x6f9580 <boost::serialization::singleton<boost::archive::detail::oserializer<boost::archive::text_oarchive, Hand> >::get_instance()::t>, ar=...,
x=0xffffe3d0) at /usr/include/boost/archive/detail/oserializer.hpp:148
#60 0x00007ffff7bae94d in save_object (bos=..., t=0xffffe3d0, ar=...,
this=0x6fe570) at libs/serialization/src/basic_oarchive.cpp:292
#61 boost::archive::detail::basic_oarchive::save_object (this=0x7fffffffdea0,
x=0xffffe3d0, bos=...) at libs/serialization/src/basic_oarchive.cpp:423
#62 0x0000000000427487 in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<Hand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:253
#63 0x0000000000426ebb in boost::archive::detail::save_non_pointer_type<boost::arch---Type <return> to continue, or q <return> to quit---
ive::text_oarchive>::invoke<Hand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#64 0x000000000042685c in boost::archive::save<boost::archive::text_oarchive, Hand const> (ar=..., t=...) at /usr/include/boost/archive/detail/oserializer.hpp:525
#65 0x0000000000426248 in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<Hand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#66 0x0000000000425c35 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<Hand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#67 0x00000000004254a0 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <Hand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#68 0x0000000000424cc9 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<Hand> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:71
#69 0x00000000004241eb in PlayerHand::serialize<boost::archive::text_oarchive> (
this=0xffffe3d0, ar=..., version=0) at src/game.cpp:362
#70 0x00000000004237f2 in boost::serialization::access::serialize<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:118
#71 0x00000000004224bb in boost::serialization::serialize<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#72 0x000000000041f533 in boost::serialization::serialize_adl<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#73 0x000000000041d634 in boost::archive::detail::oserializer<boost::archive::text_oarchive, PlayerHand>::save_object_data (
this=0x6f9550 <boost::serialization::singleton<boost::archive::detail::oserializer<boost::archive::text_oarchive, PlayerHand> >::get_instance()::t>, ar=...,
x=0xffffe3d0) at /usr/include/boost/archive/detail/oserializer.hpp:148
#74 0x00007ffff7bae94d in save_object (bos=..., t=0xffffe3d0, ar=...,
this=0x6fe570) at libs/serialization/src/basic_oarchive.cpp:292
#75 boost::archive::detail::basic_oarchive::save_object (this=0x7fffffffdea0,
x=0xffffe3d0, bos=...) at libs/serialization/src/basic_oarchive.cpp:423
#76 0x000000000042ad0f in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:253
#77 0x000000000042a33c in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::invoke<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#78 0x0000000000429a70 in boost::archive::save<boost::archive::text_oarchive, PlayerHand const> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#79 0x0000000000428fc6 in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<PlayerHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#80 0x0000000000428491 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<PlayerHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#81 0x0000000000427bb8 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <PlayerHand const> (this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#82 0x0000000000427507 in boost::serialization::nvp<PlayerHand>::save<boost::archive::text_oarchive> (this=0x7fffffffd330, ar=...)
at /usr/include/boost/serialization/nvp.hpp:79
#83 0x0000000000426f4f in boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> const> (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/access.hpp:93
#84 0x00000000004268af in boost::serialization::detail::member_saver<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> >::invoke (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/split_member.hpp:43
#85 0x00000000004262a3 in boost::serialization::split_member<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/split_member.hpp:69
---Type <return> to continue, or q <return> to quit---
#86 0x0000000000425c8f in boost::serialization::nvp<PlayerHand>::serialize<boost::archive::text_oarchive> (this=0x7fffffffd330, ar=..., file_version=0)
at /usr/include/boost/serialization/nvp.hpp:89
#87 0x0000000000425515 in boost::serialization::access::serialize<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> > (ar=..., t=...,
file_version=0) at /usr/include/boost/serialization/access.hpp:118
#88 0x0000000000424d22 in boost::serialization::serialize<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#89 0x0000000000424260 in boost::serialization::serialize_adl<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> > (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#90 0x0000000000423822 in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_only::invoke<boost::serialization::nvp<PlayerHand> > (
ar=..., t=...) at /usr/include/boost/archive/detail/oserializer.hpp:241
#91 0x00000000004224e5 in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::invoke<boost::serialization::nvp<PlayerHand> > (ar=...,
t=...) at /usr/include/boost/archive/detail/oserializer.hpp:308
#92 0x000000000041f558 in boost::archive::save<boost::archive::text_oarchive, boost::serialization::nvp<PlayerHand> const> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#93 0x000000000041d66a in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::nvp<PlayerHand> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#94 0x000000000041b8e1 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<boost::serialization::nvp<PlayerHand> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#95 0x0000000000419380 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <boost::serialization::nvp<PlayerHand> const> (
this=0x7fffffffdea0, t=...)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#96 0x0000000000416d19 in boost::archive::detail::pointer_oserializer<boost::archive::text_oarchive, PlayerHand>::save_object_ptr (
this=0x6f9650 <boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::text_oarchive, PlayerHand> >::get_instance()::t>,
ar=..., x=0xffffe3d0) at /usr/include/boost/archive/detail/oserializer.hpp:201
#97 0x00007ffff7baed85 in save_pointer (
bpos_ptr=0x6f9650 <boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::text_oarchive, PlayerHand> >::get_instance()::t>,
t=<optimized out>, ar=..., this=0x6fe570)
at libs/serialization/src/basic_oarchive.cpp:391
#98 boost::archive::detail::basic_oarchive::save_pointer (this=0x7fffffffdea0,
t=0xffffe3d0,
bpos_ptr=0x6f9650 <boost::serialization::singleton<boost::archive::detail::pointer_oserializer<boost::archive::text_oarchive, PlayerHand> >::get_instance()::t>)
at libs/serialization/src/basic_oarchive.cpp:431
#99 0x0000000000427b73 in boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::non_polymorphic::save<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:365
#100 0x00000000004274d4 in boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::save<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:460
#101 0x0000000000426f24 in boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::invoke<PlayerHand*> (ar=..., t=0xffffe3d0)
at /usr/include/boost/archive/detail/oserializer.hpp:473
#102 0x0000000000426884 in boost::archive::save<boost::archive::text_oarchive, PlayerHand* const> (ar=..., t=@0x7fffffffe3b0: 0xffffe3d0)
at /usr/include/boost/archive/detail/oserializer.hpp:525
#103 0x0000000000426278 in boost::archive::detail::common_oarchive<boost::archive::text_oarchive>::save_override<PlayerHand* const> (this=0x7fffffffdea0,
t=@0x7fffffffe3b0: 0xffffe3d0)
at /usr/include/boost/archive/detail/common_oarchive.hpp:69
#104 0x0000000000425c63 in boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<PlayerHand* const> (this=0x7fffffffdea0,
---Type <return> to continue, or q <return> to quit---
t=@0x7fffffffe3b0: 0xffffe3d0)
at /usr/include/boost/archive/basic_text_oarchive.hpp:80
#105 0x00000000004254de in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <PlayerHand* const> (this=0x7fffffffdea0,
t=@0x7fffffffe3b0: 0xffffe3d0)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:63
#106 0x0000000000424cf7 in boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator&<PlayerHand*> (this=0x7fffffffdea0,
t=@0x7fffffffe3b0: 0xffffe3d0)
at /usr/include/boost/archive/detail/interface_oarchive.hpp:71
#107 0x0000000000424219 in PlayerHand::serialize<boost::archive::text_oarchive> (
this=0x7fffffffe358, ar=..., version=0) at src/game.cpp:364
#108 0x00000000004237f2 in boost::serialization::access::serialize<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/access.hpp:118
#109 0x00000000004224bb in boost::serialization::serialize<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:69
#110 0x000000000041f533 in boost::serialization::serialize_adl<boost::archive::text_oarchive, PlayerHand> (ar=..., t=..., file_version=0)
at /usr/include/boost/serialization/serialization.hpp:128
#111 0x000000000041d634 in boost::archive::detail::oserializer<boost::archive::text_oarchive, PlayerHand>::save_object_data (
this=0x6f9550 <boost::serialization::singleton<boost::archive::detail::oserializer<boost::archive::text_oarchive, PlayerHand> >::get_instance()::t>, ar=...,
x=0x7fffffffe358) at /usr/include/boost/archive/detail/oserializer.hpp:148
#112 0x00007ffff7bae94d in save_object (bos=..., t=0x7fffffffe358, ar=...,
this=0x6fe570) at libs/serialization/src/basic_oarchive.cpp:292
#113 boost::archive::detail::basic_oarchive::save_object (this=0x7fffffffdea0,
x=0x7fffffffe358, bos=...) at libs/serialization/src/basic_oarchive.cpp:423
#114 0x000000000042ad0f in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:253
#115 0x000000000042a33c in boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::invoke<PlayerHand> (ar=..., t=...)
at /usr/include/boost/archive/detail/oserializer.hpp:308
#116 0x0000000000429a70 in boost::archive::save<boost::archive::text_oarchive, PlayerHand const> (ar=..., t=...)
找到了错误,当您保存时,您必须确定该序列时的顺序,当保存时,它必须是相同的(对于同一版本),就像加载加载时一样数据文件。最好使用操作员&lt;&lt;>>而不是&amp;对于主类和 vector ,而不是本机类数组[] ,因为boost ::序列化将更好地替换null数据,它将称呼复制构造仪查找正确的构造仪参数。Linux的问题是编译选项。