【发布时间】:2014-12-05 13:46:32
【问题描述】:
我正在尝试使用Boost 库对对象进行序列化(保存)和反序列化(重新加载),以便最大限度地减少开销内存需求,因为我创建了多个对象。我是 Boost 库的新手,但到目前为止我不想修改我正在使用的库。我尝试编写下面的代码,但出现错误 {error C2039: 'serialize' : is not a member of 'DirectedGraphicalModels::CGraph'E:\external\boost\boost_1_54_0\boost\serialization\access.hpp 118}。我正在使用的图形库的标题是here
int main(int argc, char *argv[])
{
CImageGraph *pGraph = new CGraph(nStates);
cout << "Building the Graph..." << endl;
pGraph->buildImageGraphN4(fv.rows, fv.cols, pEdgeTrainer != NULL, true);
// Save data
{
const char* fileName = "Graph.txt";
// Create an output archive
std::ofstream ofs(fileName);
boost::archive::text_oarchive ar(ofs);
// Save only the pointer. This will trigger serialization
// of the object it points too, i.e., o1.
ar & pGraph;
}
// Restore data
CImageGraph *pRGraph = new CGraph(nStates);
cout << "Building the Graph for restore..." << endl;
pRGraph->buildImageGraphN4(fv.rows, fv.cols, pEdgeTrainer != NULL, true);
pRGraph;
{
const char* fileName = "Graph.txt";
// Create and input archive
std::ifstream ifs(fileName);
boost::archive::text_iarchive ar(ifs);
// Load
ar & pRGraph;
}
// Make sure we read exactly what we saved.
assert(pRGraph != pRGraph);
//assert(*pRGraph == pRGraph);
}
请告诉我如何继续保存并重新加载图表以进行进一步处理。到目前为止,我已经参考了这篇文章1和2,但我还没有清楚地理解这些概念。 提前致谢。
【问题讨论】:
标签: c++ serialization boost