尝试使用 boost 序列化保存数据库时,遇到无法解决的段错误。你能帮忙吗?任何建议都将不胜感激。我已将以下声明确定为罪魁祸首,但不确定如何解决
oa << *this;
我的代码部分如下:
template<class Archive>
void nDB::serialize(Archive &ar, const unsigned int version) {
ar & _LAYERS;
ar & _MACROS;
ar & _MODULES;
ar & _INSTS;
}
void nDB::save_db(string filename) {
std::ofstream ofs(filename.c_str(), std::ios::out | std::ios::binary);
//assert(ofs.good());
boost::archive::binary_oarchive oa(ofs);
oa << *this;
ofs.close();
}
嗨,我能够将问题指向我数据库中的循环引用。代码如下:
template<class Archive>
void pin::serialize(Archive &ar, const unsigned int version) {
ar & pin_Port;
ar & pin_Layer;
}
和
template<class Archive>
void port::serialize(Archive & ar, const unsigned int version){
ar & port_Name;
ar & port_Use;
ar & port_Dir;
ar & port_PINS;
}
嗨,下面是我的班级定义
class pin {
public:
port* pin_Port;
layer* pin_Layer;
// rect* pin_shape;
pin();
~pin();
void set_port(port*);
void set_layer(layer*);
string get_name();
port* get_port();
layer* get_layer();
string get_layer_name();
double get_layer_width();
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version);
};
class port {
public:
string port_Name;
char port_Use;
char port_Dir;
pin_vector port_PINS;
port();
~port();
void set_name(string);
void set_use(int);
void set_dir(int);
string get_name(void);
string get_use(void);
string get_dir(void);
void add_pin(pin*);
pin_vector get_all_pins(void);
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version);
};