我使用 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/