Вам нужно показать код для класса, который содержится в boost :: array.Так как boost :: array STL-совместимый , не должно быть никаких причин, по которым это не будет работать.Вы должны делать что-то вроде классов bus_route и bus_stop в этом примере.
Класс, содержащийся в массиве boost ::, должен объявить boost :: serialization :: access как класс друга иреализовать метод сериализации, как показано ниже:
class bus_stop
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const bus_stop &gp);
virtual std::string description() const = 0;
gps_position latitude;
gps_position longitude;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar & latitude;
ar & longitude;
}
protected:
bus_stop(const gps_position & _lat, const gps_position & _long) :
latitude(_lat), longitude(_long)
{}
public:
bus_stop(){}
virtual ~bus_stop(){}
};
Как только это будет сделано, контейнер std должен иметь возможность сериализации bus_stop:
class bus_route
{
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream &os, const bus_route &br);
typedef bus_stop * bus_stop_pointer;
std::list<bus_stop_pointer> stops;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
// in this program, these classes are never serialized directly but rather
// through a pointer to the base class bus_stop. So we need a way to be
// sure that the archive contains information about these derived classes.
//ar.template register_type<bus_stop_corner>();
ar.register_type(static_cast<bus_stop_corner *>(NULL));
//ar.template register_type<bus_stop_destination>();
ar.register_type(static_cast<bus_stop_destination *>(NULL));
// serialization of stl collections is already defined
// in the header
ar & stops;
}
public:
bus_route(){}
void append(bus_stop *_bs)
{
stops.insert(stops.end(), _bs);
}
};
Обратите внимание на важную строку:
ar & stops;
, который будет автоматически перебирать контейнер std, в данном случае std :: список указателей bus_stop.
Ошибка:
error C2039: 'serialize' : is not a member of 'boost::array<T,N>'
Указывает, что класс, содержащийся вboost :: array либо не объявил boost :: serialization :: access как класс друга, либо не реализовал метод шаблона сериализации.