c++ - boost::序列化警告未使用变量 file_version

标签 c++ boost boost-serialization

我使用 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;
}

正确地提出了另一个警告。

最佳答案

您可以匿名声明参数:

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

关于c++ - boost::序列化警告未使用变量 file_version,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49408679/

相关文章:

c++ - 将元素移出关联容器

c++ - 级联阴影贴图意外行为

c++ - boost::archive::xml_iarchive 因 xml(反序列化上下文)而失败

c++ - Boost序列化无法恢复保存的对象

c++ - boost 序列化的编译错误

c++ - 定义类时对类的 undefined reference

C++:我需要释放函数内部的指针吗?

c++ - boost::asio,异步读取错误

c++ - 如何使用 Boost 实现测试套件和用例的组织?

c++ - 从 boost::compute::detail::sha1 生成 boost::uuids::uuid