【问题标题】:boost::serialization warning unusedvariable file_versionboost::序列化警告未使用变量file_version
【发布时间】:2018-08-30 17:04:31
【问题描述】:

我使用 boost::serialization 库。编译时,我收到很多冗长的警告,这些警告似乎与未在序列化函数中使用 file_version 有关。 (编译器:g++)

有没有一种聪明的方法可以明确禁用这些函数的警告,因为我一般喜欢未使用的变量警告,这有助于避免愚蠢的错误。

代码示例(非常不独立,但足以说明一点):

template<class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer; // old boost version doesn't do this for containers.
}

我只是写作的想法

template<class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
    file_version;
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer;
}

正确地提出另一个警告。

【问题讨论】:

  • @sehe 我看不到有趣的 cmets。你能解释一下这个笑话吗?你链接错误的部分吗?我不明白你在说什么。
  • "// boost bug - can't handle non copy constructability" - 这不是 boost 错误,请参阅链接(另外,funny ad.2)
  • @sehe 有评论,因为 boost 不允许我写 ar & this->layers_(如果我在 1.6.1 中正确地用谷歌搜索)
  • 1.6.1?那不是我记得看过的版本。它可能只包含某个标题,尽管我当然不知道 layers_ 的类型是什么(inb4 hash_map )。但请注意,只有在 layers_ 是固定大小的容器时,循环才会起作用。

标签: c++ boost boost-serialization


【解决方案1】:

你可以匿名声明参数:

template<class Archive>
void serialize(Archive &ar, const unsigned int /*file_version*/)
{
    ar & this->bias_;
    for(auto& layer : this->layers_)
        ar & layer; // old boost version doesn't do this for containers.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    相关资源
    最近更新 更多