错误:二进制表达式的操作数无效
error: invalid operands to binary expression
我试图从第三方编译代码,但得到了错误:
错误:二进制表达式的操作数无效
('boost::archive::binary_oachive'和'Tree*')oa<lt;这
我认为使用<<
将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;
}
}
[编辑:实际上,@LightnessRacesinOrbit所说的更有意义:你可能只需要取消引用this
指针]
似乎没有为类Tree
定义operator <<
。它需要符合boost::archive::binary_oarchive
所期望的任何格式。
operator <<
对于Tree
的定义是:
boost::archive::binary_oarchive& operator<<(boost::archive::binary_oarchive& os, const Tree& dt)
{
// TODO: serialise 'tree' into 'os'
return os;
}
如果您需要使用Tree
类的私有字段,请在Tree
的声明中放入以下内容,使其成为友元函数:
boost::archive::binary_oarchive& operator<<(boost::archive::binary_oarchive& os, const Tree& dt)
相关文章:
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 二进制表达式的操作数无效 - 使用 for 和迭代器
- int* 和 int[] 类型对二进制运算符 + 的操作数无效
- 错误:二进制'operator*' 'float'和'float[0]'类型的操作数无效
- c++ 错误:二进制"运算符+"类型"矩阵*"和"矩阵*"的操作数无效
- 二进制表达式的操作数无效?
- 二进制表达式的操作数无效("常量字符*"和"常量字符*")
- 没有变量声明为函数,但错误:二进制表达式的操作数无效
- 为什么映射迭代器显示基本操作数无效错误
- 如何修复此错误:二进制表达式的操作数无效("std::vector<double>"和"double")?
- 错误:二进制表达式的操作数无效(映射使用查找函数错误)
- C++:"错误:类型'const char*'和'const char [28]'的操作数无效到二进制'ope
- 错误:使用索引寻址和 Clang 的指令的操作数无效
- 错误:二进制'operator*' 'int [1]'和'float'类型的操作数无效
- 派生类的重载<<运算符表示操作数无效
- 错误:C++ 中二进制"operator%"类型"float"和"int"的操作数无效
- 实现 vector 时二进制表达式的操作数无效
- 提升multi_index示例:错误:二进制表达式的操作数无效
- 字符和常量字符[2] 类型的操作数无效到二进制运算符
- 二进制表达式的操作数无效("无线电设备"和"常量无线电设备")