错误:二进制表达式的操作数无效

时间:2015-02-26 22:20:32

标签: c++

我试图从第三方编译代码并得到错误:

  

错误:二进制表达式的操作数无效

     

(' boost :: archive :: binary_oarchive'和' Tree *')oa<<这;

我认为使用thisoa传递给<<是违法的。但有谁能告诉我如何开始修复它?

这是源代码:

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;
    }
}

1 个答案:

答案 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