我试图从第三方编译代码并得到错误:
错误:二进制表达式的操作数无效
(' boost :: archive :: binary_oarchive'和' Tree *')oa<<这;
我认为使用this
将oa
传递给<<
是违法的。但有谁能告诉我如何开始修复它?
这是源代码:
void save(std::string path) {
try {
std::ofstream ofs(path.c_str());
boost::archive::binary_oarchive oa(ofs);
oa << this;
ofs.flush();
ofs.close();
std::cout << "saved " << path << std::endl;
} catch (boost::archive::archive_exception& ex) {
std::cout << "Archive Exception during serializing:" << std::endl;
std::cout << ex.what() << std::endl;
std::cout << "it was tree: " << path << std::endl;
}
}
答案 0 :(得分:0)
[编辑:实际上,@ LightnessRacesinOrbit所说的更有意义:你可能只需要取消引用this
指针]
似乎operator <<
没有为班级Tree
定义。它需要符合boost::archive::binary_oarchive
期望的任何格式。
operator <<
的{{1}}定义为:
Tree
如果您需要使用boost::archive::binary_oarchive& operator<<(boost::archive::binary_oarchive& os, const Tree& dt)
{
// TODO: serialise 'tree' into 'os'
return os;
}
类的私有字段,请将以下内容放入Tree
声明中,使其成为friend函数:
Tree